#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 2 * 1e5 + 5;
int n, m, t;

int main()
{
    cin >> t;
    while (t--)
    {
        scanf("%d", &n);
        ll sum = 0;
        int a[N], s[N];
        int mx = 0;
        for (int i = 0; i < n; i++)
            scanf("%d", &a[i]);
        for (int i = 0; i < n - 1; i++)
        {
            s[i] = a[i + 1] - a[i];
        }
        for (int i = 0; i < n - 1; i++)
        {
            sum += abs(s[i]);
            if(i == n-2){
                mx = max(mx, abs(s[i]));
            }
            else {
                int q =abs(s[i])+abs(s[i+1])-abs(s[i] + s[i+1]);
                mx = max(mx,  q);
            }
        }
        mx = max(mx, abs(s[0]));
        printf("%lld\n", sum - mx);
    }
    // system("PAUSE");
    return 0;
}