#include<bits/stdc++.h>

using namespace std;

#define ios               ios_base::sync_with_stdio(false);
#define ll                long long
#define ld                long double
#define da(x,i)           cout << #x << "[" << i << "] = " << x[i] << "\n"
#define da2(x,i,y,j)      cout << #x << "[" << i << "] = " << x[i] << " ! " << #y << "[" << j << "] = " << y[j] << "\n"
#define d2a(x,i,j)        cout << #x << "[" << i << "][" << j << "] = " << x[i][j] << "\n"
#define db(x)             cout << #x << " = " << (x) << "\n"
#define db2(x,y)          cout << #x << " = " << (x) << " ! " << #y << " = " << (y) << "\n"
#define db3(x,y,z)        cout << #x << " = " << (x) << " ! " << #y << " = " << (y) << " ! " << #z << " = " << (z) << "\n"
#define db4(w,x,y,z)      cout << #w << " = " << (w) << " ! " << #x << " = " << (x) << " ! " << #y << " = " << (y) << " ! " << #z << " = " << (z) << "\n"
#define inf               LLONG_MAX



int main()
{
        ll tt; cin >> tt;
        while(tt--)
        {
                ll n; cin >> n;
                vector<ll> a(n+2,0);
                for(ll i = 1; i <= n; i++) cin >> a[i];
                ll sum = 0;
                for(ll i = n; i-1; i--) sum += abs(a[i] - a[i-1]);
                ll mn = sum - max(abs(a[1] - a[2]),abs(a[n-1] - a[n]));
                for(ll i = 2; i < n; i++)
                {
                        ll c = sum - abs(a[i] - a[i-1]) - abs(a[i] - a[i+1]) + abs(a[i-1] - a[i+1]);
                        mn = min(mn,c);
                }
                cout << mn << "\n";
        }
}





































/*

*/

































