#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define MOD (ll)1000000007
#define pii pair<int,int>
#define pll pair<ll,ll>
#define UNIQUE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end());
ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
ll power(ll a,ll b){ll ret=1;while(b){if(b%2)ret=ret*a%MOD;a=a*a%MOD;b/=2;}return ret;}

ll a[200001];

int main()
{
    int tc;
    scanf("%d",&tc);
    while(tc--)
    {
        int n;
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
            scanf("%lld",&a[i]);
        vector<ll> v;
        ll temp = 0;
        a[0] = a[n+1] = 1e18;
        for(int i=2;i<n;i++)
        {
            temp = max(temp, abs(a[i-1]-a[i]) + abs(a[i]-a[i+1])-abs(a[i+1]-a[i-1]));
        }
        temp = max(temp, abs(a[1]-a[2]));
        temp = max(temp, abs(a[n]-a[n-1]));
        ll ans = 0;
        for(int i=2;i<=n;i++)
            ans+=abs(a[i]-a[i-1]);
        printf("%lld\n",ans-temp);
    }
    return 0;
}