#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define pi  3.141592653589793238462643383279
#define int long long
#define ff first
#define ss second
#define endl '\n'
#define all(x) (x).begin(), (x).end()
#define rep(i,x,y) for(int i=(int)x; i<y; i++)
#define high_functioning_sociopath  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
const unsigned int M = 998244353;
/*_____________________________THE GAME IS ON_____________________________*/
void solve()
{
      int n;
      cin >> n;
      vector<int>v(n);
      for(int i=0;i<n;i++) cin >> v[i];
      //cout << x << endl;
      int res = 0;
      for(int i=1;i<n;i++)
      {
             res  += abs(v[i]-v[i-1]);
      }
      int i = abs(v[1]-v[0]);
      int j = abs(v[n-1]-v[n-2]);
      int k = 0;
      for(int i=1;i<n-1;i++)
      {
             int z = abs(v[i]-v[i-1]) + abs(v[i]-v[i+1]) - abs(v[i+1]-v[i-1]);
             k = max(k,z);
      }
      int y = max(i,max(j,k));
      cout << res-y << endl;
}
int32_t main()
{
   high_functioning_sociopath
   //pre();
   ll t;
   cin>>t;
   while(t--)
   {
      solve();
   }
}