#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <deque>
#include <algorithm> 
#include <cmath>

#define ll long long int
#define db double
 
using namespace std;
 
int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	int _;
	cin >> _;
	while (_--) {
		ll n;
		cin >> n;
		vector <ll> a(n);
		for (auto &i : a) cin >> i;

		ll mx = max(abs(a[n - 1] - a[n - 2]), abs(a[1] - a[0])), res = abs(a[n - 1] - a[n - 2]);

		for (int i = 0; i < n - 2; ++i) {
			res += abs(a[i + 1] - a[i]);
			mx = max(mx, (abs(a[i + 1] - a[i]) + abs(a[i + 2] - a[i + 1])) - abs(a[i + 2] - a[i]));
		}
		cout << res - mx;
		
		
 
		cout << "\n";
	}
	return 0;
}