#include "bits/stdc++.h"
#define FI first.first
#define SE first.second
#define TH second
#define fi first
#define se second
#define th second

using namespace std;

template<typename T>
string to_string(const pair<T, T>& x) {
	return "(" + to_string(x.fi) + "," + to_string(x.se) + ")";
}

template<typename T>
string to_string(const vector<T>& vc, int w) {
	if(vc.empty()) return "";
	if(w + 1 == vc.size()) return to_string(vc[w]);
	return to_string(vc[w]) + "," + to_string(vc, w + 1);
}

template<typename T>
string to_string(const vector<T>& vc) {
	return "{" + to_string(vc, 0) + "}";
}

void debug_out() { cerr << endl; }
 
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
 
#ifdef DEBUG
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

class DebugStream {}LOG;
template <typename T>DebugStream &operator<<(DebugStream &s, const T&) { return s; }
#ifdef DEBUG
#define LOG clog
#endif

typedef long long ll;
typedef pair<ll, ll> ii;
typedef long double ld;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());

const int maxN = 1e5 + 9, maxV = 1e6 + 9, MOD = 1e9 + 7, SQ = 335, lg = 20, bs = 29;

ll manh(ii a, ii b) {
	return abs(a.fi - b.fi) + abs(a.se - b.se);
}

ll alle(const vector<ii>& arr, const vector<ii>& brr) {
	ll ret = 0;
	for(int i = 0; i < 4; i++)
		ret += manh(arr[i], brr[i]);
	return ret;
}

void swpp(vector<ii>& arr) {
	for(auto& el: arr) swap(el.fi, el.se);
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	#ifdef DEBUG
	freopen("input.txt", "r", stdin);
	#endif

	clock_t begi = clock();
	int t;
	cin >> t;
	while(t--) {
		vector<ii> arr(4);
		for(auto& el: arr) cin >> el.fi >> el.se;
		sort(arr.begin(), arr.end());
		ll ans = LLONG_MAX / 3;
		for(int u = 0; u < 24; u++) {
			for(int r = 0; r < 2; r++, swpp(arr)) {
				int xCoord = arr[0].fi;
				for(int m = 0; m < 4; m++) {
					int said = abs(xCoord - arr[m].fi);
				  for(int z = 0; z < 4; z++) {
				  	int yCoord = arr[z].se;
				    for(int a = -1; a <= 1; a += 2) {
				  		for(int b = -1; b <= 1; b += 2) {
				  	    auto trg = vector<ii>({ii(xCoord, yCoord), ii(xCoord + a * said, yCoord),
																			ii(xCoord, yCoord + b * said), ii(xCoord + a * said, yCoord + b * said)});
								ans = min(ans, alle(trg, arr));
							}
						}
					}
				}
			}
			next_permutation(arr.begin(), arr.end());
		}
		cout << ans << '\n';
	}
}

