#include <bits/stdc++.h>
using namespace std;

using pii = pair<int, int>;

void solve() {
	pii p[4];
	for(int i = 0; i < 4; i++)
		cin >> p[i].first >> p[i].second;

	vector<int> d;
	for(int i = 0; i < 4; i++) {
		for(int j = 0; j < 4; j++) {
			d.push_back(abs(p[i].first - p[j].first));
			d.push_back(abs(p[i].second - p[j].second));
		}
	}

	sort(p, p + 4);

	long long res = 1e18;

	do {
		for(int l : d) {
			int x[4], y[4];
			for(int i = 0; i < 4; i++)
				tie(x[i], y[i]) = p[i];
			x[1] -= l;
			x[2] -= l;
			y[2] -= l;
			y[3] -= l;

			sort(x, x + 4);
			sort(y, y + 4);

			long long cost = 0;
			for(int i = 0; i < 4; i++) {
				cost += abs(x[1] - x[i]);
				cost += abs(y[1] - y[i]);
			}

			res = min(res, cost);

		}
	} while(next_permutation(p, p + 4));

	cout << res << '\n';
}

int main() {
	int t;
	cin >> t;
	while(t--)
		solve();	
}
