#include<bits/stdc++.h>
using namespace std;
#define sortvector(v) sort(v.begin(),v.end())
#define removedups(v) sortvector(v); v.resize(unique(v.begin(),v.end()) - v.begin());

using ll = long long int;
vector<ll> getdivs(ll n){
    vector<ll> ans;
    for(ll i = 1;i*i<=n;++i){
        if(n%i == 0){
            ans.emplace_back(i);
            if(i!=1 && n/i != i) ans.emplace_back(n/i);
        }
    }
    
    sort(ans.rbegin(),ans.rend());
    return ans;
}
template<typename T>
T square(T x){
    return x*x;
}

int main(){
    int t;
    cin >> t;
    while(t--){
       // cerr<<"CASE:"<<t<<"\n";
        int n;
        cin >> n;
        ll arr[n];
        for(int i = 0;i<n;++i){ cin >> arr[i];}
        ll answer = 0;
        for(int i = n-1;i>0;--i){
            answer += abs(arr[i]-arr[i-1]);
        }
        ll tmp_answer = answer;
        answer = min(answer,min(
                        answer - abs(arr[0]-arr[1]),
                        answer-abs(arr[n-2]-arr[n-1])));
        for(int index = 1;index < n-1;++index){
            ll ans = tmp_answer;
            ans -= abs(arr[index-1]-arr[index]);
            ans -= abs(arr[index+1]-arr[index]);
            ans += abs(arr[index+1]-arr[index-1]);
            answer = min(answer,ans);
        }
        cout << answer <<"\n";
    }
    return 0;
}