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

int T, d, posx, posy, x[5], y[5], tmpx[5], tmpy[5], pos[5];
bool vis[5];
long long mini, ans;
void cal(void)
{
	ans = 0;
	for (int i = 1; i <= 4; i++)
	{
		if (pos[i] & 1) ans += abs(x[i] - posx);
		else ans += abs(x[i] - posx - d);
		if (pos[i] >= 3) ans += abs(y[i] - posy);
		else ans += abs(y[i] - posy - d);
	}
	mini = min(mini, ans);
}
void dfs(int u)
{
	if (u == 5) cal();
	else
	{
		for (int i = 1; i <= 4; i++)
			if (!vis[i]) vis[i] = true, pos[u] = i, dfs(u + 1), vis[i] = false;
	}
}
int main()
{
	scanf("%d", &T);
	while (T--)
	{
		mini = 0x3f3f3f3f3f3f3f3fLL;
		for (int i = 1; i <= 4; i++)
			scanf("%d%d", &x[i], &y[i]), tmpx[i] = x[i], tmpy[i] = y[i];
		sort(x + 1, x + 5), sort(y + 1, y + 5);
		d = max(x[3] - x[2], y[3] - y[2]);
		posx = x[1] + max(0, x[3] - (x[1] + d)), posy = y[1] + max(0, y[3] - (y[1] + d));
		for (int i = 1; i <= 4; i++)
			x[i] = tmpx[i], y[i] = tmpy[i];
		dfs(1);
		printf("%lld\n", mini);
	}
	return 0;
}