#include <bits/stdc++.h>
#pragma GCC optimize(3)
#define int long long
#define ri register
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define is insert
#define es erase
using namespace std;
inline int read()
{
	int s=0, w=1; ri char ch=getchar();
	while(ch<'0'||ch>'9') { if(ch=='-') w=-1; ch=getchar(); }
	while(ch>='0'&&ch<='9') s=(s<<3)+(s<<1)+(ch^48), ch=getchar();
	return s*w;
}
int X[9],Y[9],p[9],a[9],b[9];
signed main()
{
	for(ri int T=read();T;T--)
	{
		for(ri int i=1;i<=4;i++)
		{
			p[i]=i;
			a[i]=read(), b[i]=read();
		}
		int Ans=1e18;
		do
		{
			for(ri int i=1;i<=4;i++) X[i]=a[p[i]], Y[i]=b[p[i]];
			int res=abs(X[1]-X[3])+abs(X[2]-X[4])+abs(Y[1]-Y[2])+abs(Y[3]-Y[4]);
			int lx,rx,ly,ry;
			lx=min(X[2],X[4])-max(X[1],X[3]), rx=max(X[2],X[4])-min(X[1],X[3]);
			ly=min(Y[3],Y[4])-max(Y[1],Y[2]), ry=max(Y[3],Y[4])-min(Y[1],Y[2]);
			if(rx>=0&&ry>=0)Ans=min(Ans,res+max(0ll,max(lx,ly)-min(rx,ry))*2);
		}while(next_permutation(p+1,p+5));
		printf("%lld\n",Ans);
	}
	return 0;
}
 	 	 	     	 	 	 	   	 	 	 	  	