#include<bits/stdc++.h>
using namespace std;
#define dlwlrma ios::sync_with_stdio(0); cin.tie(0);
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pii pair<int,int>
#define f first
#define s second
#define INF (0x3f3f3f3f)

const int mxN = 2e5+2;
ll n,a[mxN];
void solve(){
    cin >> n;
    for(int i = 0; i < n; i++) cin >> a[i];
    ll ans = 0;
    for(int i = 1; i < n; i++) 
        ans+=abs(a[i]-a[i-1]);
    ll s = max(abs(a[1]-a[0]),abs(a[n-1]-a[n-2]));
    for(int i = 1; i < n-1; i++){
        s = max(s,abs(a[i]-a[i-1])+abs(a[i+1]-a[i])-abs(a[i+1]-a[i-1]));
    }
    cout << ans-s << '\n';
}

int main(){
    dlwlrma
    int T;
    cin >> T;
    while(T--){
        solve(); 
    }
}

