#include <bits/stdc++.h>
#include <iostream>
#include <sstream>

using namespace std;
#define gc getchar_unlocked
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
#define ll long long
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define minel *min_element
#define mxel *max_element
#define setp(n) setprecision(n) << std::fixed
#define sz(x) int((x).size())
typedef pair<int, int> pii;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpii;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
int mpow(int base, int exp);
void ipgraph(int m);
//void dfs(int u, int par);
const int mod = 1000000007 ;
const int N = 1e6 + 16, M = N;
const int LN = 1e9;
//const int LLN = 1e16;
ll dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

using namespace std;

//set insert,erase, count

//next_permutation(permutation.begin(),permutation.end())

ll gcd(ll a, ll b)
{
  
  if (b == 0)
    return a;
  return gcd(b, a % b);
}
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }
//ll fexp(ll a, ll b){ll ans = 1;while(b){if(b&1) ans = ans*a%MOD; b/=2;a=a*a%MOD;}return ans;}
//ll inverse(ll a, ll p){return fexp(a, p-2);}
// bool sortbysec(const pll &a, const pll &b){return (a.second < b.second);}
//void ingraph(vvl& graph, ll m){ll x, y;fo(i, m){cin>>x>>y;x--, y--;graph[x].pb(y);graph[y].pb(x);}}
//ll modify(ll n){ll res = n;res%=MOD;res+=MOD;res%=MOD;return res;}

struct cmp
{
  bool operator()(const pii &a, const pii &b)
  {
    int len1 = a.S - a.F + 1;
    int len2 = b.S - b.F + 1;

    if (len1 == len2)
    {
      return a.F < b.F;
    }
    return len1 > len2;
  }
};

ll fac[N], inv[N], b[N];

int mpow(int base, int exp)
{
  base %= mod;
  int result = 1;
  while (exp > 0)
  {
    if (exp & 1)
      result = ((ll)result * base) % mod;
    base = ((ll)base * base) % mod;
    exp >>= 1;
  }
  return result;
}

void pre()
{
  int i;
  fac[0] = inv[0] = 1;
  fac[1] = inv[1] = 1;
  Fo(i, 2, N)
  {
    fac[i] = (i * fac[i - 1]) % mod;
    inv[i] = (mpow(i, mod - 2) * inv[i - 1]) % mod;
  }
}
ll C(int n, int r)
{
  if (r > n)
    return 0;
  ll ans = fac[n];
  ans *= inv[r];
  ans %= mod;
  ans *= inv[n - r];
  ans %= mod;
  return ans;
}

ll n;

vi permutation;
int chosen[100] = {0};

ll power(ll a, ll b)
{
  ll ans = 1;
  while (b--)
    ans *= a;

  return ans;
}
ll k;


ll m;

vi positions[1005];
//vi a1(1005);
int bk[1005];

// int calcmex()
// {
//   int mex = n;

//   memset(bk, 0, sizeof(bk));

//   fo(j, n)
//   {
//     bk[a1[j]] = 1;
//   }

//   fo(j, n + 2)
//   {
//     if (bk[j] == 0)
//     {
//       mex = j;
//       break;
//     }
//   }

//   return mex;
// }
int link[N], size[N];

// int find(int a){
//   while(link[a]!=a)a = link[a];
//   return a;
// }

// int same(int a,int b){
//   return (find(a) == find(b));
// }

// void unite(int a, int b){

//   a = find(a);
//   b = find(b);

//   // if(size[a]<size[b])swap(a,b);

//   // size[a]+=size[b];

//   link[b] = a;

// }

// void prepare(int n){
//   fo(i,n){
//     link[i]=i;
//     size[i]=1;
//   }
// }
bool isPrime(ll x) {
    for (ll d = 2; d * d <= x; d++) {
        if (x % d == 0)
            return false;
    }
    return true;
}

bool comparator(tuple<int, int, int> a, tuple<int, int, int> b)
{

  if (get<0>(a) != get<0>(b))
  {
    return get<0>(a) > get<0>(b);
  }

  return (get<1>(a)) < (get<1>(b));
}
vector<ll> primes;

void sieve()
{
  int n = 1e6;
  int primess[n];
  memset(primess, 0, sizeof(primess));

  for (int i = 2; i * i <= n; i++)
  {
    if (primess[i] == 0)
    {
      primes.pb(i);
      fo(j, n)
      {
        if (i * (j + 1) >= n)
          break;

        primess[i * (j + 1)] = -1;
      }
    }
  }
}
int visited[26] = {0};
// int visitable[1000][1000] = {0};
 vi adj[26];
 set<int> deg[100006];
 vi radj[100006];
 int sub[100006] = {-1};
// int colors[1000006] = {0};

// int subtree[1000006] = {0};
// int cnt =0;

// char s[1000][1000];
vi ans;
vpii moves = {{0, 1}, {1, 0},  {0, -1},{-1, 0}};



int mandist(pii x1, pii x2){
  return abs(x1.F - x2.F) + abs(x1.S-x2.S);
}

bool valid(int i,int j){
  return i>=0 &&i<n&&j>=0&&j<m ;
}

bool cycledetected = false;

void dfs(int s,  int e){

  // cout<<"Entered "<<s<<" from" << e<<endl;

  if(visited[s]==2)return;



  if(visited[s]==1){
    cycledetected = true;
    return;
  }

  visited[s]=1;


  for(auto xx: adj[s]){

    if(xx == e)continue;
    if(visited[xx]!=2){
      dfs(xx,s);
    }
  }
  ans.pb(s);
  visited[s]=2;

  // cout<<"Exited "<<s<<endl;
}


vector<long long> trial_division1(long long n) {
    vector<long long> factorization;
    for (long long d = 2; d * d <= n; d++) {
        while (n % d == 0) {
            factorization.push_back(d);
            n /= d;
        }
    }
    if (n > 1)
        factorization.push_back(n);
    return factorization;
}

void solve()
{

  int n;
  cin>>n;
  vi a1(n);

  fo(i,n)cin>>a1[i];

  ll maxsave = 0;

  fo(i,n){
    int cursave = 0;

    if(i==0){
      cursave = abs(a1[i+1]-a1[i]);

    }
    else if(i== n-1){
      cursave = abs(a1[n-2]- a1[n-1] );
    }
    else{
      if(a1[i]<a1[i+1] && a1[i]<a1[i-1]){
        cursave = min(a1[i+1], a1[i-1]) - a1[i];
        cursave = cursave*2;
      }
      else if(a1[i]>a1[i+1] && a1[i]>a1[i-1]){
        cursave = a1[i] - max(a1[i+1], a1[i-1]);
        cursave = cursave*2;
      }
    }

    maxsave = max((ll)cursave, maxsave);

  }

  ll count = 0;

  fo(i,n-1){
    count+= abs(a1[i+1] - a1[i]);

  }

  // deb2(maxsave,  count);

  cout<<count-maxsave<<endl;







}

//While checking consecutive equality in for loop, make sure you check count after loop
//ends
//madarchod... ll ka dekhlo
//ee

int main()
{
#ifndef ONLINE_JUDGE
  freopen("./input.txt", "r", stdin);
  freopen("./output.txt", "w", stdout);

#endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll t;
  t = 1;
  cin>>t;

  while (t--)
  {

    solve();
  }
}
