#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
 
// using namespace __gnu_pbds;
using namespace std;
 
#define fbo find_by_order
#define ook order_of_key
#define fi first
#define se second
#define long long long
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
const int INF = 1e9;
const long LINF = 1e18;
// const long MOD = 1e9+7; // 998244353 
// template <typename T> T mul(T a, T b) { return (1LL*a*b)%MOD; }
// template <typename T> T add(T a, T b) { return ((a+b))%MOD; }
// template <typename T, typename... V> T mul(T t, V... v) { return mul(t,mul(v...)); }
// template <typename T, typename... V> T add(T t, V... v) { return add(t,add(v...)); }
// typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
// mt19937_64 rng(std::chrono::system_clock::now().time_since_epoch().count());
// inv[1] = 1;
// fac[0] = ifac[0] = 1;
// for(int i = 2; i <= 500000; i++) inv[i]=MOD-(MOD/i)*inv[MOD%i]%MOD;
// for(int i = 1; i <= 500000; i++) fac[i] = mul(1LL*i, fac[i-1]), ifac[i] = mul(inv[i], ifac[i-1]);
// long C(int n, int k) { return (k > n)? 0 : mul(fac[n], ifac[n-k], ifac[k]); }
// /mnt/c/Users/vince/Desktop/POST-IOI/
long X[4], Y[4];

int main()
{
	// ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	// freopen("input.in", "r", stdin);
	int t; scanf("%d", &t);
	while(t--)
	{
		for(int i = 0; i < 4; i++)
			scanf("%lld %lld", &X[i], &Y[i]);
		vector<int> vec = {0, 1, 2, 3};
		long ans = LINF;
		do
		{
			long cnt = 0;
			long a = LINF, b = -LINF;
			long c = LINF, d = -LINF;
			long e = LINF, f = -LINF;
			long g = LINF, h = -LINF;

			for(int i = 0; i < 4; i++)
			{
				int x = vec[i];
				if(x&1)
				{
					a = min(X[i], a);
					b = max(X[i], b);
				}
				else
				{
					c = min(X[i], c);
					d = max(X[i], d);
				}
				if(x&2)
				{
					e = min(Y[i], e);
					f = max(Y[i], f);
				}
				else
				{
					g = min(Y[i], g);
					h = max(Y[i], h);
				}
			}
			if(d < a) continue;
			if(h < e) continue;
			// printf("%d %d %d %d\n", vec[0], vec[1], vec[2], vec[3]);
			// printf("%lld %lld %lld %lld %lld %lld %lld %lld\n", a, b, c, d, e, f, g, h);
			cnt = b-a + d-c + f-e + h-g;
			int kir1 = max(c-b, 0LL), kan1 = d-a;
			int kir2 = max(g-f, 0LL), kan2 = h-e;
			if(kan1 < kir2 || kan2 < kir1)
			{
				cnt += (max(kir1,kir2)-min(kan1,kan2))*2;
			}
			ans = min(ans, cnt);
		}while(next_permutation(vec.begin(), vec.end()));
		printf("%lld\n", ans);
	}
}











