#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define vll vector<ll>
#define pii pair<ll, ll>
#define vb vector<bool>
#define pb push_back
#define mp make_pair
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define rrep(a, b, c, d) for(ll a = b; a > c; a-=d)
#define rep(a, b, c, d) for(ll a = b; a < c; a+=d)
#define tests ll t; cin >> t; while(t--)
#define inf 2000000000000000000

void solution(){
	ll n, ans=0, mx=0; cin >> n; vll a(n);
	rep(i, 0, n, 1) cin >> a[i];
	rep(i, 1, n, 1) ans += abs(a[i]-a[i-1]);
	mx = max(abs(a[1]-a[0]), abs(a[n-1]-a[n-2]));
	rep(i, 1, n-1, 1) mx = max(mx, abs(a[i]-a[i-1])+abs(a[i+1]-a[i])-abs(a[i+1]-a[i-1]));
	ans -= mx;
	cout << ans << '\n';
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	tests solution();
	return 0;
}