#include <bits/stdc++.h>
using namespace std;
typedef long long ll;

template<typename T>
void out(T x) { cout << x << endl; exit(0); }

const int maxn = 1e6 + 7;

ll solve() {
    int n; cin >> n;
    vector<ll> v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }

    ll og = 0LL;
    for (int i = 1; i < n; i++) {
        og += abs(v[i]-v[i-1]);
    }

    ll ans = og;

    for (int i = 1; i < n; i++) {
        // choose v[i-1] for both v[i-1], v[i]
        ll temp = og;
        temp -= abs(v[i]-v[i-1]);
        if (i+1 < n) {
            temp -= abs(v[i]-v[i+1]);
            temp += abs(v[i-1]-v[i+1]);
        }
        ans = min(ans,temp);

        // choose v[i] for both v[i-1], v[i]
        temp = og;
        temp -= abs(v[i]-v[i-1]);
        if (i-2 >= 0) {
            temp -= abs(v[i-2]-v[i-1]);
            temp += abs(v[i-2]-v[i]);
        }
        ans = min(ans,temp);
    }

    return ans;
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int T; cin >> T;
    while (T--) {
        cout << solve() << "\n";
    }
    
    
    return 0;
}
