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

void solve(){
	int n;
	cin>>n;
	
	vector<ll>a(n);
	
	for(int i=0; i<n; i++)
		cin>>a[i];
	
	ll x = 0;
	
	for(int i=1; i<n; i++)
		x += abs(a[i] - a[i-1]);
		
	ll a1 = abs(a[0] - a[1]);
	ll an = abs(a[n-1] - a[n-2]);
	
	ll ai = 0;
	for(int i=1; i<n-1; i++)
		ai = max(ai, abs(a[i] - a[i-1]) + abs(a[i] - a[i+1]) - abs(a[i-1] - a[i+1]));
		
	ll y = max(max(a1, an), ai);
	
	cout<<x-y<<"\n";
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int t;
	cin>>t;
	
	while(t--)
		solve();
}

