#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
 
#define lp(var,start,end) for (ll var = start; var <end ; ++var)
#define rlp(var,start,end) for(ll var = start; var>=end ; var--)
#define pb push_back
#define mp make_pair
#define pf push_front
#define ff first
#define ss second
#define vll vector<ll>
#define vld vector<ld>
#define pll pair<ll,ll> 
#define pld pair<ld,ld> 
#define vpll vector<pll>
#define vpld vector<pld>
#define all(X) X.begin(),X.end()
#define endl "\n"
#define sz(x) ((ll)((x).size()))

const ll N=1e5+5,inf=1e18;

int main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	ll t;
	cin >> t;
	while(t--)
	{
		ll n;
		cin >> n;
		ll ary[n];
		vpll v;
		lp(i,0,n)
		{
			cin >> ary[i];
			v.pb({ary[i],i});
		}
		ll ans=0;
		lp(i,0,n-1)
		{
			ans+=abs(ary[i]-ary[i+1]);
		}
		ll mn=ans;
		lp(i,0,n)
		{
			if(i==0)
			{
				ll d=abs(ary[i]-ary[i+1]);
				mn=min(mn,ans-d);
			}
			else if(i==n-1)
			{
				ll d=abs(ary[i]-ary[i-1]);
				mn=min(mn,ans-d);
			}
			else
			{
				ll d1=abs(ary[i]-ary[i+1]);
				ll d2=abs(ary[i]-ary[i-1]);
				ll d3=abs(ary[i+1]-ary[i-1]);
				mn=min(mn,ans-d1-d2+d3);
			}

		}
		cout<<mn<<endl;
	}	
	return 0;
}