#include <bits/stdc++.h>
using namespace std;
long long x[10], y[10];

long long cal2(long long x1, long long y1, long long x2, long long y2) {
	return abs(x1 - x2) + abs(y1 - y2);
}

typedef pair< long long, long long > pii;

long long cal(long long x1, long long x2, long long y1) {
	long long res = 0x3f3f3f3f3f;
	vector< pii > V;
	V.push_back(make_pair(x1, y1));
	V.push_back(make_pair(x2, y1));
	V.push_back(make_pair(x1, y1 + x2 - x1));
	V.push_back(make_pair(x2, y1 + x2 - x1));
	for (int i = 0; i < 4; i++) {
		for (int j = 0; j < 4; j++)
			if (i != j) {
				for (int k = 0; k < 4; k++)
					if (k != i && k != j) {
						for (int t = 0; t < 4; t++) {
							if (t != i && t != j && t != k) {
								long long tmp = cal2(V[i].first, V[i].second, x[1], y[1])
									+ cal2(V[j].first, V[j].second, x[2], y[2])
									+ cal2(V[k].first, V[k].second, x[3], y[3])
									+ cal2(V[t].first, V[t].second, x[4], y[4]);
								res = min(res, tmp);
							}
						}
					}
			}
	}
	return res;
}

int main() {
	int T;
	scanf("%d", &T);
	while (T--) {
		for (int i = 1; i <= 4; i++) {
			scanf("%lld %lld", &x[i], &y[i]);
		}
		long long res = 0x3f3f3f3f3f;
		for (int i = 1; i <= 4; i++) {
			for (int j = 1; j <= 4; j++)
				if (i != j) {
					for (int k = 1; k <= 4; k++) {
						res = min(res, cal(x[i], x[j], y[k]));
					}
				}
		}
		for (int i = 1; i <= 4; i++) {
			swap(x[i], y[i]);
		}
		for (int i = 1; i <= 4; i++) {
			for (int j = 1; j <= 4; j++)
				if (i != j) {
					for (int k = 1; k <= 4; k++) {
						res = min(res, cal(x[i], x[j], y[k]));
					}
				}
		}
		printf("%lld\n", res);
	}
}