
#include <bits/stdc++.h>
#define fastio()                  \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define pb push_back
#define show(x) cout << (#x) << " : " << x << endl;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pow power
#define mp make_pair
#define ff first
#define ss second
#define pii pair<ll, ll>
#define sq(x) ((x) * (x))
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define siz(a) int((a).size())
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))
#define endl "\n"
#define pi 3.14159265
const ll mod = 1000 * 1000 * 1000 + 7;
const ll mod1 = 998244353;
const ll INF     = 1ll*1000*1000*1000*1000*1000*1000 + 7; 
using namespace std;

ll power(ll x, ll y) 
{ 
   ll res = 1;      
  
   
    while (y > 0) 
    { 
       
        if (y & 1) 
            res = (long long)(res*x); 
  

        y = y>>1; 

        x = (long long)(x*x);

        //cout<<x<<'\n'; 
    } 
    return res; 
} 






int main()
{

#ifndef ONLINE_JUDGE    
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
#endif

fastio();

    ll T;
    cin>>T;

    while(T--)
    {

        ll n;
        cin>>n;
        vector <ll> a(n);

        For(i,0,n)
        cin>>a[i];

        ll sum=0;
        for(int i=0;i<n-1;i++) {
            sum+=abs(a[i]-a[i+1]);
        }
        ll ans=INF;
        for(int i=0;i<n;i++) {
            if (i==0) {
                sum-=abs(a[0]-a[1]);
                ans=min(ans,sum);
                sum+=abs(a[0]-a[1]);
            } else if (i==n-1) {
                sum-=abs(a[n-2]-a[n-1]);
                ans=min(ans,sum);
                sum+=abs(a[n-2]-a[n-1]);
            } else {
                sum-=abs(a[i]-a[i-1]);
                sum-=abs(a[i]-a[i+1]);
                sum+=abs(a[i-1]-a[i+1]);
                ans=min(ans,sum);
                sum+=abs(a[i]-a[i-1]);
                sum+=abs(a[i]-a[i+1]);
                sum-=abs(a[i-1]-a[i+1]);

            }
        }
        cout<<ans<<endl;

    }

return 0;
}

// check all product based operations for integer overflow


