/******************************************
* AUTHOR : RTG *
******************************************/
#include <bits/stdc++.h>
using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	#ifndef ONLINE_JUDGE 
    // For getting input from input.txt file 
    freopen("input.txt", "r", stdin); 
    // Printing the Output to output.txt file 
    freopen("output.txt", "w", stdout); 
	#endif 

    int t;
    cin>>t;
    while(t--){
    	int n;
    	cin>>n;
    	vector<long long>a(n);
    	long long ans=0;
    	// vector<long long>dd;
    	cin>>a[0];
    	for(int i=1;i<n;i++){
    		cin>>a[i];
    		long long dif=abs(a[i]-a[i-1]);
    		// dd.emplace_back(dif);
    		ans+=dif;
    	}
    	long long r=ans;
    	// cout<<ans<<" ans\n";
    	r=min(ans-abs(a[0]-a[1]),ans-abs(a[n-1]-a[n-2]));
    	for(int i=1;i<n-1;i++){
    		if((a[i]>a[i+1]&&a[i]>a[i-1])||(a[i]<=a[i+1]&&a[i]<=a[i-1])){
    			long long dif = abs(a[i]-a[i+1])+abs(a[i]-a[i-1]);
    			long long ch = abs(a[i-1]-a[i+1]);
    			r=min(ans-(dif-ch),r);
    		}
    	}
    	cout<<r<<'\n';
    }
	return 0;
}