﻿#include<iostream>
#include<math.h>
#include<algorithm>
#include <stdlib.h>  

using namespace std;

long long a[300002];
int main()
{
	ios_base::sync_with_stdio(false);  
	cin.tie(NULL);  
	cout.tie(NULL);
	int T;
	int n;
	long long m, ans;
	cin >> T;
	while (T--)
	{
		cin >> n;
		ans = 0;
		m = 0;
		for (int i = 0; i < n; ++i)
		{
			cin >> a[i];
			if(i >= 1)ans += abs(a[i] - a[i - 1]);
			if (i >= 2)
			{
				m = max(m, abs(a[i] - a[i - 1]) + abs(a[i - 1] - a[i - 2]) - abs(a[i] - a[i - 2]));
			}
		}
		m = max(m, abs(a[0] - a[1]));
		m = max(m, abs(a[n-1] - a[n-2]));
		cout << ans - m << '\n';
	}
}