#include<bits/stdc++.h>
using namespace std;
const int M  = 100005;
long long int N = 1e9 + 7;
long long int Z = 998244353;
#define ll long long int

void precompute(){

}
int max3(int x, int y, int z){
    return max(x, max(y,z));
}
long long int dist(int a, int b, int c, int d){
	long long int z = abs(c-a) + abs(d-b);

	return z;
}
bool compare(const pair<int, int> &p1, const pair<int, int> &p2){
    return (p1 < p2);
}
int findmin(int a[], int b[], int x1, int x2, int y1, int y2){
	long long int minm = N;
	minm = minm * 1000;
	vector<int> v = {0, 1, 2, 3};
	do {
		minm = min(minm, dist(a[v[0]], b[v[0]], x1, y1) + dist(a[v[1]], b[v[1]], x1, y2) + dist(a[v[2]], b[v[2]], x2, y1) + dist(a[v[3]], b[v[3]], x2, y2));
	}
	while(next_permutation(v.begin(), v.end()));
	return minm;
}
int main(){
    #ifdef SARTHAK
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    auto start = chrono::high_resolution_clock::now(); 
    #endif 
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int t=1; 
    cin>>t;
    precompute();
    while(t--){
        int x[4], y[4], old_x[4], old_y[4];
        for(int i = 0; i<4; i++){
        	cin>>x[i]>>y[i];
        	old_x[i] = x[i];
        	old_y[i] = y[i];
        }
        sort(x, x + 4);
        sort(y, y + 4);
        int b_a_u = x[3] - x[0];
        int b_a_l = x[2] - x[1];
        int d_c_u = y[3] - y[0];
        int d_c_l = y[2] - y[1];
        int l = min(b_a_u, d_c_u);
        int x1 = max(x[0], x[2] - l);
        int x2 = x1 + l;
        int y1 = max(y[0], y[2] - l);
        int y2 = y1 + l;
        cout<<findmin(old_x, old_y, x1, x2, y1, y2)<<"\n";
    }
    #ifdef SARTHAK
    auto end = chrono::high_resolution_clock::now(); 
    double time_taken =  chrono::duration_cast<chrono::nanoseconds>(end - start).count(); time_taken *= 1e-9; 
    cout << "\nTime taken by program is : " << fixed << time_taken << setprecision(9); cout << " sec" << endl; 
    #endif
   	return 0;
}
