#include<bits/stdc++.h>

using namespace std;

const long long INF64=(long long)1e18;

pair <long long,long long> p[4];

bool read(){
	for(int i=0;i<4;i++){
		if(!(cin>>p[i].first>>p[i].second))
			return false;
	}
	return true;
}

void solve(){
	long long ans=INF64;
	for(int st=0;st<2;st++){
		for(int idx1=0;idx1<4;idx1++) for(int idx2=0;idx2<4;idx2++) for(int idy1=0;idy1<4;idy1++){
			long long x1=p[idx1].first;
			long long x2=p[idx2].first;
			long long y1=p[idy1].second;

			if(x1>x2)
				continue;

			for(int k=-1;k<=1;k+=2){
				long long y2=y1+k*abs(x1-x2);

				vector < pair <long long,long long> > fp={{x1,y1},{x2,y1},{x2,y2},{x1,y2}};
				sort(fp.begin(),fp.end());

				do{
					long long cur=0;
					for(int i=0;i<4;i++)
						cur+=abs(fp[i].first-p[i].first)+abs(fp[i].second-p[i].second);

					ans=min(ans,cur);
				}while(next_permutation(fp.begin(),fp.end()));
			}
		}

		for(int i=0;i<4;i++)
			swap(p[i].first,p[i].second);
	}
	cout<<ans<<endl;
}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie();
	cout.tie();

	cout<<fixed<<setprecision(15);

	int tt;
	cin>>tt;
	while(tt--){
		read();
		solve();
	}

	return 0;
}
