#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <set>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const ll maxn = 2e5 + 5;
const ll inf = 0x3f3f3f3f3f3f3f3f;
#define P pair<ll, ll>
inline ll cal(ll x, ll y, ll xx, ll yy) {
    return max(0LL, min(y, yy) - max(x, xx) + 1);
}
P po[10];
inline void inputt() {
    for (int i = 1; i <= 4; ++i) {
        scanf("%lld%lld", &po[i].first, &po[i].second);
    }
}
ll L1, L2, R1, R2, U1, U2, D1, D2;
ll x[5], y[5];
void cal2() {
    L1 = min(po[1].first, po[3].first);
    L2 = max(po[1].first, po[3].first);
    R1 = min(po[2].first, po[4].first);
    R2 = max(po[2].first, po[4].first);
    U1 = max(po[1].second, po[2].second);
    U2 = min(po[1].second, po[2].second);
    D1 = max(po[3].second, po[4].second);
    D2 = min(po[3].second, po[4].second);
    x[0] = 0, x[1] = L1, x[2] = L2, x[3] = R1, x[4] = R2;
    y[0] = 0, y[1] = U1, y[2] = U2, y[3] = D1, y[4] = D2;
}
int main() {
    int T;
    scanf("%d", &T);
    while (T--) {
        inputt();
        sort(po+1,po+1+4);
        ll ans = inf;
        do {
            ll minx = inf, maxx, miny = inf, maxy;
            ll tp1 = 0;
            tp1 += abs(po[1].first - po[3].first);
            tp1 += abs(po[2].first - po[4].first);
            tp1 += abs(po[1].second - po[2].second);
            tp1 += abs(po[3].second - po[4].second);
            cal2();
            ll tsb = cal(L1, L2, R1, R2);
            if (!tsb) {
                minx = min(minx, abs(x[1] - x[3]));
                minx = min(minx, abs(x[1] - x[4]));
                minx = min(minx, abs(x[2] - x[3]));
                minx = min(minx, abs(x[2] - x[4]));
            } else {
                minx = 0;
            }
            minx = max(L1, R1) - min(R2, L2);
            if (cal(U2, U1, D2, D1))
                miny = 0;
            else {
                miny = min(miny, abs(y[1] - y[3]));
                miny = min(miny, abs(y[1] - y[4]));
                miny = min(miny, abs(y[2] - y[3]));
                miny = min(miny, abs(y[2] - y[4]));
            }
            maxx = max({L1, L2, R1, R2}) - min({L1, L2, R1, R2});
            maxy = max({U1, U2, D1, D2}) - min({U1, U2, D1, D2});
            int flag1 = cal(minx, maxx, miny, maxy);
            int flag2 = maxx < miny;
            if (flag2 && !flag1) {
                ans = min(ans, tp1 + (miny - maxx) * 2);
                continue;
            }
            if (flag1) {
                ans = min(ans, tp1);
            } else {
                ans = min(ans, tp1 + (minx - maxy) * 2);
            }
        } while (next_permutation(po + 1, po + 1 + 4));
        printf("%lld\n", ans);
    }
    return 0;
}