#include<bits/stdc++.h>
#define f(i,j,n,c) for(int i=j;i<n;i+=c)
typedef long long ll;
using namespace std;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int t=1;
	cin>>t;
	while(t--)
	{
		ll n;
		cin>>n;
		int a[n];
		for(int i=0;i<n;i++)cin>>a[i];
		ll ans=0,m=1e18;
		for(int i=1;i<n;i++)
		{
			ans+=abs(a[i]-a[i-1]);
		}
		//cout<<ans<<endl;
		for(int i=1;i<n-1;i++)
		{
			ll x=ans-abs(a[i]-a[i-1])-abs(a[i]-a[i+1]);
			//cout<<x<<endl;
			m=min(m,x+abs(a[i-1]-a[i+1]));
		}
		//cout<<ans<<endl;
		//cout<<ans<<endl;
		ll x=ans-abs(a[1]-a[0]);
		m=min(m,x);
		ans-=abs(a[n-1]-a[n-2]);
		m=min(m,ans);
		cout<<m;
		cout<<endl;
	}
}
