#include<iostream>
#include<cmath>
using namespace std;

typedef long long ll;

inline ll max(ll a, ll b){ return a > b ? a : b; }

int main()
{
    ll T;
    scanf("%I64d", &T);
    while(T--)
    {
        ll n, num[200010];
        scanf("%I64d", &n);
        if(n == 2)
        {
            scanf("%I64d %I64d", &num[1], &num[2]);
            printf("0\n");
            continue;
        }

        for(ll i = 1; i <= n; i++) scanf("%I64d", &num[i]);

        ll res = 0;
        res += abs(num[n]-num[n-1]);
        
        ll maxn = -1;  //maxn : 删去后对答案的贡献
        for(ll i = 2; i <= n-1; i++) 
        {
            res += abs(num[i]-num[i-1]); //先算出不删去的总次数
            ll a = num[i-1], b = num[i], c = num[i+1];
            maxn = max(maxn, abs(a-b)+abs(b-c)-abs(a-c));  // 贡献
        }

        if(maxn < abs(num[1]-num[2])) maxn = abs(num[1]-num[2]);
        if(maxn < abs(num[n]-num[n-1])) maxn = abs(num[n]-num[n-1]);

        res -= maxn;
        printf("%I64d\n", res);
    }
    //system("pause");
    return 0;
}
