#include <bits/stdc++.h>
#define fst first
#define snd second
#define fore(i,a,b) for(int i=a,ThxDem=b;i<ThxDem;++i)
#define pb push_back
#define ALL(s) s.begin(),s.end()
#define FIN ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define SZ(s) int(s.size())
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;

ii want[4],vv[4],v[4];

ll get(ii a, ii b){return abs(a.fst-b.fst)+abs(a.snd-b.snd);}

ll res=1e18;

ll get(ll len, ll x, ll y){
	want[0]={x,y};
	want[1]={x+len,y};
	want[2]={x+len,y+len};
	want[3]={x,y+len};

	fore(i,0,4) fore(j,0,4) if(i!=j){
		ii concha={-1,-1};
		fore(k,0,4) if(k!=i&&k!=j){
			if(concha.fst==-1) concha.fst=k;
			else concha.snd=k;
		}
		
		ll now=get(v[i],want[0])+get(v[j],want[1]);
		if(now>res)continue;
		ll v1=get(v[concha.fst],want[2])+get(v[concha.snd],want[3]);
		ll v2=get(v[concha.fst],want[3])+get(v[concha.snd],want[2]);
		now+=min(v1,v2);
		res=min(res,now);
	}
	
	return 1e18;
}

//y
ll solve(ll len, ll x){
	ll ans=1e18;
	fore(i,0,4){
		ans=min(ans,get(len,x,v[i].snd));
		ans=min(ans,get(len,x,v[i].snd+len));
		ans=min(ans,get(len,x,v[i].snd-len));
	}
	return ans;
}

ll mnx,mxx,mny,mxy;

unordered_set<ll> did;

//x
ll solve(ll len){
	if(did.count(len))return 1e18;
	did.insert(len);
	ll ans=1e18;
	fore(i,0,4){
		ans=min(ans,solve(len,v[i].fst));
		ans=min(ans,solve(len,v[i].fst+len));
		ans=min(ans,solve(len,v[i].fst-len));
	}
	return ans;
}

//lado
ll solve(){
	ll ans=1e18;
	fore(i,0,4) fore(j,i+1,4){
		ans=min(ans,solve(abs(v[i].fst-v[j].fst)));
		ans=min(ans,solve(abs(v[i].snd-v[j].snd)));
	}
	return ans;
}

int main(){FIN;
	int t; cin>>t;
	while(t--){
		res=1e18;
		did.clear();
		fore(i,0,4) cin>>v[i].fst>>v[i].snd;
		solve();
		cout<<res<<"\n";
	}
}