#include <bits/stdc++.h>

#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef array<int, 3> a3;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<ii> vii;

const int N=2*1e5+5;

int n;
ll a[N];

ll f(int i)
{
    return abs(a[i]-a[i+1]);
}

void solve()
{
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i];

    ll ans=0;
    for (int i=1;i<n;i++) ans+=f(i);

    ll x=ans;
    ans-=max(f(1), f(n-1));

    for (int i=2;i<n;i++)
    {
        ans=min(ans, x-f(i-1)-f(i)+abs(a[i-1]-a[i+1]));
    }
    cout<<ans<<"\n";
}

int main()
{
//	freopen(".inp","r",stdin);
//	freopen(".out","w",stdout);

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

	int t;cin>>t;
	while (t--) solve();

	return 0;
}
