#include<bits/stdc++.h>

using namespace std;

#define ll long long 

int main(){
	ll t ; cin >> t ;
	while(t--){
		ll n ; cin >> n ;
		vector<ll>v(n); 
		ll ans = 0 ;
		ll sum = 0 ;
		for (int i = 0; i < n; i++) { cin >> v[i] ;if(i) sum+=abs(v[i]-v[i-1]) ;}
		ans = max(abs(v[0]-v[1]),abs(v[n-1]-v[n-2]));
		for (int i = 1 ; i < n-1; i++)
		{
			ans = max(ans , (abs(v[i]-v[i-1])+abs(v[i+1]-v[i]))-abs(v[i+1]-v[i-1]));
		}
		cout <<sum - ans << endl;
	} 
	
}





