#include <iostream>
#include <climits>
#include <algorithm>
#include <vector>
using ll = long long;
int main(){
	int t{0};
	std::cin >> t;
	std::vector<ll> results;
	while(t--){
		int n{0};
		std::cin >> n;
		std::vector<int> arr(n);
		for(auto &val: arr)
			std::cin >> val;
		ll maxCost = 0;
		for(int i{1}; i < n; i++){
			maxCost += abs(arr[i] - arr[i - 1]);
		}
		int maxRed = std::max(abs(arr[1] - arr[0]), abs(arr[n - 1] - arr[n - 2]));
		for(int i{1}; i < n - 1; i++){
			auto curr = abs(arr[i + 1] - arr[i]) + abs(arr[i] - arr[i - 1]) - abs(arr[i + 1] - arr[i -1]);
			maxRed = std::max(maxRed, curr);
		}
		results.push_back(maxCost - maxRed);
	}
	for(auto &result : results)
		std::cout << result << '\n';
	return 0;
}