#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>

#define pb push_back
#define mp makr_pair

typedef long long ll;
typedef double db;
const int Maxn = 2e5+10;
const int Inf = 0x7f7f7f7f;

using namespace std;

int n, a[Maxn];
void solve(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++)  scanf("%d",&a[i]);
    int maxx = -1;
    for(int i = 2;i<n;++i)maxx = max(maxx,abs(a[i]-a[i-1])+abs(a[i+1]-a[i])-abs(a[i+1]-a[i-1]));
    ll ans = 0;
    maxx = max(abs(a[2]-a[1]),maxx);
    maxx = max(abs(a[n]-a[n-1]),maxx);
//    for(int i = 2;i<n;++i)if(maxx==abs(a[i]-a[i-1])+abs(a[i+1]-a[i])){
//        ans+=abs(a[i+1]-a[i-1]);
//        break;
//    }
    for(int i = n;i>=2;--i)ans+=abs(a[i]-a[i-1]);
    ans-=maxx;
    printf("%lld\n",ans);
}

int main(){
    int T;
    scanf("%d",&T);
    while( T-- )
    {
        solve();
    }
    return 0;
}
