Code
#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll abss(ll a){
if (a<0)
return -a;
return a;
}
ll maxx(ll a,ll b){
if (a>b)
return a;
return b;
}
int main(){
int n;
ll a[200005];
ll x,y,ans;
int t;
cin>>t;
while (t--){
cin>>n; y=0; x=0;
for (int i=0; i<n; i++)
cin>>a[i];
for (int i=1; i<n-1; i++){
x+=abss(a[i]-a[i-1]);
y=maxx(y,abss(a[i]-a[i-1])+abss(a[i+1]-a[i])-abss(a[i+1]-a[i-1]));
}
x+=abss(a[n-1]-a[n-2]);
y=maxx(y,abss(a[n-1]-a[n-2]));
y=maxx(y,abss(a[1]-a[0]));
ans=x-y;
cout<<ans<<endl;
}
return 0;
}