#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define deb(x) cout << #x << " " << x << "\n"

int main() {
    #ifndef ONLINE_JUDGE 
        freopen("input.txt", "r", stdin); 
        freopen("output.txt", "w", stdout); 
    #endif
    ll t=1;
    cin >> t;
    while(t--){
        ll n;
        cin >> n;
        vector <ll> v(n);
        for(ll i=0;i<n;i++){
            cin >> v[i];
        }
        ll sum=0;
        for(ll i=0;i<n-1;i++){
            sum+=abs(v[i]-v[i+1]);
        }
        ll del;
        for(ll i=0;i<n;i++){
            if(i==0){
                del = abs(v[i]-v[i+1]);
            }
            else if(i==n-1){
                del = max(del,abs(v[i]-v[i-1]));
            }
            else{
                del = max(del,abs(v[i]-v[i+1])+abs(v[i]-v[i-1])-abs(v[i-1]-v[i+1]));
            }
        }
        // deb(del);
        cout << sum-del << "\n";
    }
    return 0;
}