#include<bits/stdc++.h>
using namespace std ;

#define pb(v) push_back(v) 
#define mp(u,v) make_pair(u,v) 

int main(){
    int t ;
    cin>>t ;
    while(t--){
        int n ; cin>>n;
        int a[n];
        vector<pair<int,int>> peak ;
        for(int i =0 ;i <n ;i++){
            cin>>a[i];
        }
        if(n==1||n==2){
            cout<<0<<endl;
            continue;
        }
        
        peak.pb(mp(0,abs(a[0]-a[1])));
        for(int i = 1 ; i< n-1;i++){
           
           peak.pb(mp(abs(a[i-1]-a[i+1]),abs(a[i]-a[i+1])+abs(a[i]-a[i-1])));
            
        }
       
        peak.pb(mp(0,abs(a[n-1]-a[n-2])));
        int max =INT_MIN ; int maxind = -1;
        for(int i =0;i<n ;i++){
                if(max<peak[i].second - peak[i].first){
                    max = abs(peak[i].first - peak[i].second);
                    maxind = i;
                }
            }
           
        
         
        if( peak[0].second >=max){
            max = abs(peak[0].second);
            maxind =0;
        }
        
        if( peak[n-1].second >=max){
            max = abs(peak[n-1].first);
            maxind =n-1;
        }
        //cout<<"hi"<<endl;
        if( maxind == 0){
            a[0]=a[1];
        }
        else if(maxind == n-1){
            a[n-1]=a[n-2];
        }
        else{
            a[maxind]=a[maxind+1];
        }
        //cout<<"maxind : " <<maxind <<" "<<a[maxind]<<endl;
        long long op =0;
        for(int i = n-1;i>=1;i--){
            op+=abs(a[i]-a[i-1]);
        }
        cout<<op<<endl;
    }
}
/*
0
1
3
4
6
5
2847372102
0
1
4
4
6
5
2847372102
*/