//#pragma GCC optimize(2)
//#pragma GCC optimize("Ofast","inline","-ffast-math")
//#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<iostream>
#include<cstdio>
#include<string>
#include<ctime>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<stack>
#include<climits>
#include<queue>
#include<map>
#include<set>
#include<sstream>
#include<cassert>
#include<bitset>
using namespace std;

typedef long long LL;

typedef unsigned long long ull;

const LL inf=0x3f3f3f3f3f3f3f3f;

const int N=1e6+100;

struct Node
{
	LL x,y;
	void input()
	{
		scanf("%lld%lld",&x,&y);
	}
}p[4];

int id[4];

pair<LL,LL>get_seg(LL a,LL b)
{
	return make_pair(min(a,b),max(a,b));
}

pair<LL,LL>get_interval(pair<LL,LL>a,pair<LL,LL>b)
{
	return make_pair(
		max({0LL,a.first-b.second,b.first-a.second}),
		max({0LL,b.second-a.first,a.second-b.first})
	);
}

LL get_len(pair<LL,LL>a)
{
	return a.second-a.first;
}

int main()
{
#ifndef ONLINE_JUDGE
//  freopen("data.ans.txt","r",stdin);
//  freopen("data.out.txt","w",stdout);
#endif
//  ios::sync_with_stdio(false);
	int w;
	cin>>w;
	while(w--)
	{
		for(int i=0;i<4;i++)
		{
			p[i].input();
			id[i]=i;
		}
//		01
//		23
		LL ans=inf;
		do
		{
			LL cur=0;
			auto x1=get_seg(p[id[0]].x,p[id[2]].x);
			auto x2=get_seg(p[id[1]].x,p[id[3]].x);
			auto Seg_x=get_interval(x1,x2);
			cur+=get_len(x1)+get_len(x2);
			
			auto y1=get_seg(p[id[0]].y,p[id[1]].y);
			auto y2=get_seg(p[id[2]].y,p[id[3]].y);
			auto Seg_y=get_interval(y1,y2);
			cur+=get_len(y1)+get_len(y2);
			
			LL delta=max(max(Seg_x.first,Seg_y.first)-min(Seg_x.second,Seg_y.second),0LL);
			cur+=2*delta;
			ans=min(ans,cur);
		}while(next_permutation(id,id+4));
		printf("%lld\n",ans);
	}













    return 0;
}
 					  		  	 						  	   	 			