#include <bits/stdc++.h>
#define nput(a) cout << a << endl
#define sput(a) cout << a << ' '
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
int INF = 1e9;
ll a[maxn], b[maxn], c[maxn];
void solve() {
    int n, MAX = -INF, index = 0;
    ll res = 0;
    cin >> n;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        b[i] = a[i];
        c[i] = a[i];
    }
    for (int i = n - 1; i > 0; i--) {
        res += abs(a[i] - a[i - 1]);
    }
    ll ans = -INF;
    ans = abs(a[0] - a[1]);
    for (int i = 1; i < n - 1; i++) {
        ll r = abs(a[i + 1] - a[i]) + abs(a[i] - a[i - 1]);
        ans = max(ans, r - (abs(a[i + 1] - a[i - 1])));
    }
    ans = max(ans, abs(a[n - 1] - a[n - 2]));
    if(n==2){
        cout<<'0'<<endl;
        return;
    }
    cout << res - ans << endl;
}
int main() {
    ios::sync_with_stdio(false);
    int t;
    cin >> t;
    while (t--) {
        solve();
    }
    return 0;
}