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

const ll INF = 1e18;

ll f1(ll a, ll b, ll c, ll d, ll len_tmp) {
	ll val_1 = min(abs(a-d), abs(b-c));
	ll val_2 = max(abs(a-d), abs(b-c));
	ll ret;
	// if (len_tmp < val_1) {
	// 	ret = abs(a-d)+abs(b-c)-4*len_tmp;
	// } else if (len_tmp < val_2) {
	// 	ret = abs(a-d)+abs(b-c)-4*val_1;
	// } else {
	// 	ret = abs(a-d)+abs(b-c)-4*val_1+4*(len_tmp-val_2);
	// }
	if (len_tmp < val_1) {
		ret = abs(a-d)+abs(b-c)-2*len_tmp;
	} else if (len_tmp < val_2) {
		ret = abs(a-d)+abs(b-c)-2*val_1;
	} else {
		ret = abs(a-d)+abs(b-c)-2*val_1+2*(len_tmp-val_2);
	}
	return ret;
}

ll f2(ll a, ll b, ll c, ll d, ll len_tmp) {
	ll val_1, val_2;
	if ((a<=c && d<=b) || (c<=a && b<=d)) {
		val_1 = min(abs(a-b), abs(c-d));
		val_2 = max(abs(a-b), abs(c-d));
	} else {
		val_1 = min(abs(a-d), abs(b-c));
		val_2 = max(abs(a-d), abs(b-c));
	}
	ll ret;
	// if (len_tmp < val_1) {
	// 	ret = abs(a-b)+abs(c-d);
	// } else if (len_tmp < val_2) {
	// 	ret = abs(a-b)+abs(c-d)+2*(len_tmp-val_1);
	// } else {
	// 	ret = abs(a-b)+abs(c-d)+2*(val_2-val_1)+4*(len_tmp-val_2);
	// }
	if (len_tmp < val_1) {
		ret = abs(a-b)+abs(c-d);
	} else if (len_tmp < val_2) {
		// ret = abs(a-b)+abs(c-d)+(len_tmp-val_1);
		ret = abs(a-b)+abs(c-d);
	} else {
		ret = abs(a-b)+abs(c-d)+2*(len_tmp-val_2);
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);

	int t;
	cin >> t;
	for (int i=0;i<t;i++) {
		vector<ll> x(4), y(4);
		for (int j=0;j<4;j++) {
			cin >> x[j] >> y[j];
		}
		vector<int> arr = {0, 1, 2, 3};
		ll ans = INF;
		vector<ll> len_candidate;
		len_candidate.push_back(0LL);
		for (int j=0;j<4;j++) {
			for (int k=j+1;k<4;k++) {
				len_candidate.push_back(abs(x[j]-x[k]));
				len_candidate.push_back(abs(y[j]-y[k]));
			}
		}
		do {
			for (auto len_tmp : len_candidate) {
				ll ans_tmp = 0LL;
				// x group: (0, 1), (2, 3)
				ll min_x_1 = min(x[arr[0]], x[arr[1]]);
				ll max_x_1 = max(x[arr[0]], x[arr[1]]);
				ll min_x_2 = min(x[arr[2]], x[arr[3]]);
				ll max_x_2 = max(x[arr[2]], x[arr[3]]);
				if ((max_x_1 < min_x_2) || (max_x_2 < min_x_1)) {
					ans_tmp += f1(min_x_1, max_x_1, min_x_2, max_x_2, len_tmp);
				} else {
					ans_tmp += f2(min_x_1, max_x_1, min_x_2, max_x_2, len_tmp);
				}
				// y group: (0, 2), (1, 3)
				ll min_y_1 = min(y[arr[0]], y[arr[2]]);
				ll max_y_1 = max(y[arr[0]], y[arr[2]]);
				ll min_y_2 = min(y[arr[1]], y[arr[3]]);
				ll max_y_2 = max(y[arr[1]], y[arr[3]]);
				if ((max_y_1 < min_y_2) || (max_y_2 < min_y_1)) {
					ans_tmp += f1(min_y_1, max_y_1, min_y_2, max_y_2, len_tmp);
				} else {
					ans_tmp += f2(min_y_1, max_y_1, min_y_2, max_y_2, len_tmp);
				}
				if (ans_tmp == 8) {
					// cout << len_tmp << "\n";
					ll x_add = 0LL;
					if ((max_x_1 < min_x_2) || (max_x_2 < min_x_1)) {
						x_add += f1(min_x_1, max_x_1, min_x_2, max_x_2, len_tmp);
					} else {
						x_add += f2(min_x_1, max_x_1, min_x_2, max_x_2, len_tmp);
					}
					ll y_add = 0LL;
					if ((max_y_1 < min_y_2) || (max_y_2 < min_y_1)) {
						y_add += f1(min_y_1, max_y_1, min_y_2, max_y_2, len_tmp);
					} else {
						y_add += f2(min_y_1, max_y_1, min_y_2, max_y_2, len_tmp);
					}
					// cout << "x_add, y_add: " << x_add << " " << y_add << "\n";
					// cout << min_x_1 << " " << max_x_1 << " " << min_x_2 << " " << max_x_2 << "\n";
					// cout << min_y_1 << " " << max_y_1 << " " << min_y_2 << " " << max_y_2 << "\n";
				}
				ans = min(ans, ans_tmp);
			}
		} while (next_permutation(arr.begin(), arr.end()));

		cout << ans << "\n";
	}
}