


#include <bits/stdc++.h>

using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
#define ll long long
#define mod 1000000007
#define ffor(i,a,b) for(int i=a;i<b;i++)
#define bfor(i,a,b) for(int i=a-1;i>=b;i--)
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define mem(x,y) memset(x,y,sizeof(x))
#define all(x) x.begin(),x.end()
#define SP(x) setprecision(x)
#define sz(x) (int)x.size()
#define fast  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define PI 3.14159265358979323846
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
ll powr(ll a,ll b)
{
	ll res=1;
	while(b)
	{
		if(b&1)res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
 
void flag(ll fl){
 
	if(fl)
	cout<<"NO";
	else
	cout<<"YES";
}
void dfs(int v,int u,vector<int>& vec,vector<vector<int>>& al)
{
    if(vec[v]>0)
    vec[v]+=vec[u];
    for(auto x:al[v])
    {  if(x!=u)
        dfs(x,v,vec,al);
    } 
}
int main()
{
    
    int t;
    cin>>t;
    while(t--)
    {
       int n;
       cin>>n;
       ll arr[n];
       ffor(i,0,n) cin>>arr[i];
       ll aa=0;
       ffor(i,0,n-1) aa=aa+abs(arr[i]-arr[i+1]);
       ll xa=0;
       ffor(i,1,n-1)
       {
           ll x=(arr[i-1]+arr[i+1])/2;
           xa=max(abs(abs(arr[i-1]-x)+abs(arr[i+1]-x)-(abs(arr[i-1]-arr[i])+abs(arr[i+1]-arr[i]))),xa);
       }
        xa=max(abs(arr[0]-arr[1]),xa);
        xa=max(abs(arr[n-2]-arr[n-1]),xa);
        cout<<aa-xa<<endl;
    }
}
