#include <bits/stdc++.h>
using namespace std;

struct point{
public:
    int x, y;
};

bool cmpx(point a, point b){
    return a.x<b.x;
}

bool cmpy(point a, point b){
    return a.y<b.y;
}

int main(){
    int t, i, j, x1, x2, y1, y2, d;
    point ptsx[4], ptsy[4];
    cin>>t;
    for(j=0; j<t; j++){
        for(i=0; i<4; i++) cin>>ptsx[i].x>>ptsx[i].y;
        sort(ptsx, ptsx+4, cmpx);
        for(i=0; i<4; i++) ptsy[i]=ptsx[i];
        sort(ptsy, ptsy+4, cmpy);
        x1=ptsx[1].x;
        x2=ptsx[2].x;
        y1=ptsy[1].y;
        y2=ptsy[2].y;
        if(x2-x1>=y2-y1){
            d=x2-x1-y2+y1;
            y2=min(y2+d, ptsy[3].y);
            d=x2-x1-y2+y1;
            y1-=d;
            cout<<x1-ptsx[0].x+ptsx[3].x-x2+min(abs(ptsx[0].y-y1)+abs(ptsx[1].y-y2), abs(ptsx[0].y-y2)+abs(ptsx[1].y-y1))+min(abs(ptsx[2].y-y1)+abs(ptsx[3].y-y2), abs(ptsx[2].y-y2)+abs(ptsx[3].y-y1))<<endl;
        }
        else{
            d=y2-y1-x2+x1;
            x2=min(x2+d, ptsx[3].x);
            d=y2-y1-x2+x1;
            x1-=d;
            cout<<y1-ptsy[0].y+ptsy[3].y-y2+min(abs(ptsy[0].x-x1)+abs(ptsy[1].x-x2), abs(ptsy[0].x-x2)+abs(ptsy[1].x-x1))+min(abs(ptsy[2].x-x1)+abs(ptsy[3].x-x2), abs(ptsy[2].x-x2)+abs(ptsy[3].x-x1))<<endl;
        }
    }
}
