#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <cstring>
#include <stack>
#include <queue>
#include <map>
#include <vector>
#include <list>
#include <set>
#include <functional>
#include <fstream>
#include <iomanip>
#include <cstdlib>
#include <cctype>
#include <ctime>
using namespace std;
typedef long long ll;
const int inf = 0x3f3f3f3f;


int q;
struct Node{
	ll x, y;
} p[4], p2[4];//点编号0,1,2,3
void exeCute()//execute the algorithm
{
	long long ans = 9e18;
	for (int i = 0; i < 4; i++)
		cin >> p[i].x >> p[i].y;
	int s[4] = {0,1,2,3};//约定0,1,2,3依次为左上,右上,左下,右下
	do{
		ll cnt = 0;
		for (int i = 0; i < 4; i++)
			p2[i].x = p[i].x, p2[i].y = p[i].y;
		//找出最优位置
		ll up = max(p2[s[0]].y, p2[s[1]].y);
		ll up1 = min(p2[s[0]].y, p2[s[1]].y);
		ll down = min(p2[s[2]].y, p2[s[3]].y);
		ll down1 = max(p2[s[2]].y, p2[s[3]].y);
		ll lf = min(p2[s[0]].x, p2[s[2]].x);
		ll lf1 = max(p2[s[0]].x, p2[s[2]].x);
		ll ri = max(p2[s[1]].x, p2[s[3]].x);
		ll ri1 = min(p2[s[1]].x, p2[s[3]].x);
		if (down > up)
			up = down;
		if (lf > ri)
			lf = ri;

		if (up - down > ri - lf){
			ll gap = (up - down) - (ri - lf);
			if (gap <= (up - up1) + (down1 - down))
				if (gap <= (up - up1))
					up -= gap;
				else {
					down += (gap - (up - up1));
					up = up1;
				}
			else{
				ri += (gap - (up - up1) - (down1 - down));
				up = up1, down = down1;
			}
		}
		else {
			ll gap = (ri - lf) - (up - down);
			if (gap <= (ri - ri1) + (lf1 - lf))
				if (gap <= (ri - ri1))
					ri -= gap;
				else {
					lf += (gap - (ri - ri1));
					ri = ri1;
				}
			else{
				up += (gap - (ri - ri1) - (lf1 - lf));
				ri = ri1, lf = lf1;
			}
		}

		//s[0],s[1],向上对齐
		cnt += abs(p2[s[0]].y - up);
		cnt += abs(p2[s[1]].y - up);
		//s[2],s[3],向下对齐
		cnt += abs(p2[s[2]].y - down);
		cnt += abs(p2[s[3]].y - down);	
		//s[0],s[2],向左对齐
		cnt += abs(p2[s[0]].x - lf);
		cnt += abs(p2[s[2]].x - lf);
		//s[1],s[3],向右对齐
		cnt += abs(p2[s[1]].x - ri);
		cnt += abs(p2[s[3]].x - ri);
		ans = min(ans, cnt);
	}while (next_permutation(s, s + 4));
	cout << ans << endl;
}

void init()//input and other initiation
{
	cin >> q;
	for (int i = 0; i < q; i++)
		exeCute();
}

int main(int argc, char * argv[]) 
{
	init();
    return 0;
}