#include <bits/stdc++.h>

using namespace std;

int main() {
    int t;
    cin>>t;
    while(t--){
        int n;
        cin>>n;
        vector<long long> v(n);
        for(int i=0;i<n;i++)
        cin>>v[i];
        
        long long ans=0;
        long long maxx=0;
        ans+=abs(v[0]-v[1]);
        maxx=max(maxx,abs(v[0]-v[1]));
        maxx=max(maxx,abs(v[n-2]-v[n-1]));
        for(int i=1;i<=n-2;i++){
            ans+=abs(v[i]-v[i+1]);
            long long val = abs(v[i]-v[i+1]) + abs(v[i]-v[i-1]) - abs(v[i-1]-v[i+1]);
            maxx=max(maxx,val);
            //cout<<abs(v[i]-v[i+1])<<" "<<abs(v[i]-v[i+1])<<" "<<abs(v[i-1]+v[i+1])<<" "<<val<<"\n";
        }
        //cout<<ans<<" "<<maxx;
        ans-=maxx;
        
        cout<<ans<<"\n";
    }
}