#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define x first
#define y second

using namespace std;
typedef long long LL;
typedef pair<LL , LL> PII;

const LL INF = 0x3f3f3f3f , N = 100010;
LL turn[4] = {0 , 1 , 2 , 3};
PII p[4];

LL cal()
{
    PII b = p[turn[0]] , c = p[turn[1]] , 
        d = p[turn[2]] , a = p[turn[3]];
    
    LL xl = min(abs(max(a.x , c.x) - min(b.x , d.x)) , 
                abs(min(a.x , c.x) - max(b.x , d.x)));
    LL xr = max(abs(max(a.x , c.x) - min(b.x , d.x)) , 
                abs(min(a.x , c.x) - max(b.x , d.x)));
    LL yl = min(abs(max(a.y , b.y) - min(c.y , d.y)) , 
                abs(min(a.y , b.y) - max(c.y , d.y)));
    LL yr = max(abs(max(a.y , b.y) - min(c.y , d.y)) , 
                abs(min(a.y , b.y) - max(c.y , d.y)));
    
    LL res = max(a.x , c.x) - min(a.x , c.x)
           + max(b.x , d.x) - min(b.x , d.x)
           + max(a.y , b.y) - min(a.y , b.y)
           + max(c.y , d.y) - min(c.y , d.y)
           + 2 * max(0LL , max(xl , yl) - min(xr , yr));
          
    return res;
}

int main()
{
    LL T;
    cin >> T;
    while(T--)
    {
        for(LL i = 0 ; i < 4 ; i++)
            cin >> p[i].x >> p[i].y;
            
        for(int i = 0 ; i < 4 ; i++)
            turn[i] = i;
            
        LL res = -1;
        do{
            if(res < 0) res = cal();
            res = min(res , cal());
        }while(next_permutation(turn , turn + 4));
        cout << res << endl;
    }
}