                              //ABHISHEK AGRAWAL,BIT mesra//                    
                      //Newbie......You have to be odd to be no. ONE :)//
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ld long double
#define fl float
#define lcm(a,b) (a*(b/__gcd(a,b)))
#define vs vector <string>
#define vc vector <char>
#define vii vector<int>
#define vll vector<ll>
#define sll set<ll>
#define pii pair<int,int>
#define plc pair<ll,char>
#define tlll tuple<ll,ll,ll>
#define mt make_tuple
#define vpll vector<pair<ll,ll>>
#define vpii vector<pair<int,int>>
#define vtll vector<tuple<ll,ll,ll>>
#define vvll vector<vector<ll>>
#define lb lower_bound
#define pb push_back
#define pob pop_back
#define f first
#define s second
#define mll map<ll,ll>
#define mp make_pair
#define sp(n) fixed<<setprecision(n)
#define mcl map<char,ll>
#define msl map<string,ll>
#define mod (ll)1000000007
#define flash ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL); 
#define test ll t;read(t);while(t--) 
#define sortv(v) sort(v.begin(),v.end())
#define INF (ll)(1e15)
#define loop(i,n) for(int i=0;i<n;i++)
#define loop1(i,n) for(int i=1;i<=n;i++)
#define rloop(n,i) for(int i=n-1;i>=0;i--)
#define loopab(i,a,b,c) for(int i=a;i<=b;i+=c)
#define reada(a,n) loop(i,n) cin>>a[i];
#define reada1(a,n) loop1(i,n) cin>>a[i];
#define sorta(a) sort(a,a+n,greater<ll>())
#define countone(n) __builtin_popcount(n)
#define numoftrailzero(n) __builtin_ctz(n)
#define maxpowoftwo(n) __builtin_clz(n)
#define leastindexwithone(n)  __builtin_ffs(n)
#define what_is(x) cerr << #x << " is " << x << endl;
#define pfv(v) cout<<v.size()<<"\n";loop(i,v.size()) cout<<v[i]<<" ";cout<<"\n";
#define pv(v) loop(i,v.size()) cout<<v[i]<<" ";
#define all(v) v.begin(),v.end()
#define mset(dp,val) memset(dp,val,sizeof(dp))
//if we need to devide any given number in powers of term the power of max term
#define answer(n) ceil(log2(n+1))
 ll q,n;ll sum,ans;
ll gcd(ll a, ll b){if (b==0){return a;} return gcd(b,a%b);}
ll powe(ll a,ll b){ll res=1;while(b>0){if(b%2 ==1){res=(res*a);}a=(a*a);b/=2;} return res;}
ll power(ll a,ll b,ll M){a%=M;ll res=1;while(b>0){if(b%2 ==1){res=(res*a)%M;}a=(a*a)%M;b/=2;} return res;}
ll extendedEuclid(ll A,ll B,ll &x,ll &y){
    if(B == 0) {
        x = 1;
        y = 0;
        return A;
    }
    else {
        ll x1 , y1;
        ll gcd = extendedEuclid(B,A%B,x1,y1);
        y = x1-(A/B)*y1; 
        x = y1;
        return gcd;
    }
}
ll mi(ll A, ll M){ll x,y;extendedEuclid(A,M,x,y);if(x<0){x+=M;} return x;}
vector<bool>sieve(1000020,true);
void Sieve(){
 sieve[0]=false;
 sieve[1]=false;
 for(ll i=2;i*i<=1000020;i++){
  if(sieve[i]==true){
   for(ll j=i*i;j<1000020;j+=i)
    sieve[j]=false;
  }
 }
}
// ll sieve_spf[1000010];
// ll n1=1000000;
// void Sieve_spf(){
//  loop(i,n1) sieve_spf[i]=i;
//   sieve_spf[0]=-1;
//   sieve_spf[1]=1;
//   for(int i=2;i<n1;i+=2) sieve_spf[i]=2;
//   for(ll i=3;i<n1;i+=2){
//     if(sieve_spf[i]==i){
//       for(ll j=(i*i);j<n1;j+=i){
//         if(sieve_spf[j]==j) sieve_spf[j]=i;
//       }
//     }
//   }
// }
// #ifdef TESTING 
// #define DEBUG fprintf(stderr, "====TESTING====\n") 
// #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl 
// #define debug(...) fprintf(stderr, __VA_ARGS__) 
// #else 
// #define DEBUG 
// #define VALUE(x) 
// #define debug(...) 
// #endif
// bool isUpcase(char c){
//     if(c >= 'A'&&c <= 'Z') return true;
//     5,5,else return false;
// }
// bool islowcase(char c){
//     if(c >= 'a'&&c <= 'z') return true;
//     else return false;
// }
const int nax=3e5+5;
ll fact[nax];
void F(){
 fact[0]=1;
 for(int i=1;i<nax;i++){
  fact[i]=fact[i-1]*i;
  fact[i]%=mod;
 }
}
ll nCr(ll n,ll r,ll M){
 if(n<r)return 0;
 return (((fact[n]*mi(fact[r],M))%M)*mi(fact[n-r]%M,M))%M;
}
// ll nCr(ll n,ll r){
//  ll res=1;
//  for(int i=0;i<r;i++){
//   res*=(n-i);
//  }
//  return res/fact[r];
// }
void the_happiest_place_on_earth()
{
    flash;
  #ifdef ENABLE_FILE_IO
    freopen("out.txt", "r", stdin);
    freopen("out1.txt", "w", stdout);
  #endif      
} 
bool comp(const pair<ll,ll> &a, const pair<ll,ll> &b){
 return (a.f-a.s<=b.f-b.s);
}
const int N=200040;ll a[N],b[N],c[N],par[N],Size[N],present[N],color[N];

ll nn;
// ll solve(int index,ll cur,ll tot){
//   if(index==n) return tot;
//   if(cur>a[index]+n/2) return INF;
//   if(dp[cur]!=INF) return dp[cur];
//   return min(solve(index+1,cur+1,tot+abs(cur-a[index])),solve(index,cur+1,tot));
// }

ll dp[200010][35];
void buildsparsh(){
  for(int j=1;(1<<j)<=n;j++)
    for(int i=1;(i+powe(2,j)-1)<=n;i++)
      dp[i][j]=min(dp[i][j-1],dp[i+powe(2,j-1)][j-1]);
}
int query(int l,int r){
  int j=log2(r-l+1);
  return min(dp[l][j],dp[r-powe(2,j)+1][j]);
}
// // int binsearch(int start,int lo,int hi,int sgcd){
// //   while(lo<hi){
// //     int mid=(lo+1+hi)/2;
// //     if(query(start,mid)==sgcd) lo=mid;
// //     else hi=mid-1;
// //   }
// //   return lo;
// // }
// // mll m;
// void solve(){
//   loop1(i,n){
//     int curgcd=a[i];
//     int curlo=i;
//     while(1){
//       int in=binsearch(i,curlo,n,curgcd);
//       m[curgcd]+=(in-curlo+1);
//       if(in==n) break;
//       curlo=in+1;
//       curgcd=query(i,curlo);
//     }
//   }
// }
bool check(){
  loop(i,n) b[i]=a[i];
  sort(b,b+n);
  int f=0;
  loop(i,n) {if(b[i]!=a[i]) return false;}
  return true;

}
void testcase(){ 
  cin>>n;
  loop1(i,n) cin>>a[i];
  vll v;
  sum=0;
  for(int i=2;i<=n;i++) v.pb(abs(a[i]-a[i-1])),sum+=abs(a[i]-a[i-1]),b[i]=sum;
  b[n+1]=b[n];
  // loop(i,n+2) cout<<b[i]<<" ";
  // cout<<"\n";
  loop(i,n+2) c[i]=sum-b[i];
  //loop(i,n+2) cout<<c[i]<<" ";
  ans=LLONG_MAX;
  loop1(i,n){
    if(i!=1&&i!=n) ans=min(ans,b[i-1]+c[i+1]+abs(a[i+1]-a[i-1]));
    else ans=min(ans,b[i-1]+c[i+1]);
  }
  cout<<ans;
  cout<<"\n";
  return;
}


int main(){
  the_happiest_place_on_earth();
  // //Today's thought: Push yourself,because no one else is going to do it for you.
  // //Things are not always #000000 and #FFFFFF
  // //START OF PROGRAM LOGIC
  // //g++ -o a BB.cpp -DENABLE_FILE_IO;./a
  //g++ -std=c++17 -Wshadow -Wall -g -fsanitize=address -fsanitize=undefined -D_GLIBCXX_DEBUG -o a file_name.cpp;./a
  //F();
  
  q=1;int t=0;
  cin>>q;  
  while(q--){
    //cout<<"Case #"<<++t<<": ";
    testcase();
  } 
  // cerr << "Time : " << 1000 *((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
  // //END OF PROGRAM LOGIC
  
 
	return 0;
}
/*
######  ###### #     # ####### #     # ##### #     #    #    ####### ####### ######
#     # #      ##    # #     # ##   ##   #   ##    #   # #      #    #     # #     #
#     # #      # #   # #     # # # # #   #   # #   #  #   #     #    #     # #     #
#     # #####  #  #  # #     # #  #  #   #   #  #  # #     #    #    #     # ######
#     # #      #   # # #     # #     #   #   #   # # #######    #    #     # #   #
#     # #      #    ## #     # #     #   #   #    ## #     #    #    #     # #    #
######  ###### #     # ####### #     # ##### #     # #     #    #    ####### #     #
*/
 