﻿#include<bits/stdc++.h>
#define N 200100
#define ll long long
using namespace std;
const ll inf=9223372036854775807;
ll n,m;
ll T;
ll a[N];
ll maxx=-inf;
ll ans;
ll anss;
int main(){
	cin>>T;
	while(T--){
		ans=0;
		maxx=-inf;
		cin>>n;
		scanf("%lld",&a[1]);
		for(int i=2;i<=n;i++){
			scanf("%lld",&a[i]);
			//maxx=max(maxx,abs(a[i]-a[i-1]));
			ans+=abs(a[i]-a[i-1]);
		}
		anss=ans;
		anss=min(anss,ans-abs(a[2]-a[1]));
		anss=min(anss,ans-abs(a[n]-a[n-1]));
		for(int i=2;i<=n-1;i++){
			anss=min(anss,ans-abs(a[i+1]-a[i])-abs(a[i-1]-a[i])+abs(a[i-1]-a[i+1]));
			//anss=min(anss,ans-abs(a[i-1]-a[i])+abs(a[i-1]-a[i+1]));
		}
		cout<<anss<<endl;
	}
	return 0;
}