#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

typedef long long ll;
typedef unsigned long long ull;
typedef long double LD;
const int INF = 2147483647;
const int INF2 = 0x3f3f3f3f;
const ll INF64 = 4e18;
const double INFD = 1e30;
const double EPS = 1e-9;
const double PI = std::acos(-1);
const int MOD = 100000007;
template <typename T>
inline T read() {
    T X = 0, w = 0;
    char ch = 0;
    while (!isdigit(ch)) {
        w |= ch == '-';
        ch = getchar();
    }
    while (isdigit(ch)) X = (X << 3) + (X << 1) + (ch ^ 48), ch = getchar();
    return w ? -X : X;
}
const int MAXN = 505;
const int MAXV = 305;
int n, m, k;
int dr[4] = {1, 0, -1, 0};
int dc[4] = {0, 1, 0, -1};
int dr2[8] = {1, 1, 1, -1, -1, -1, 0, 0};
int dc2[8] = {1, 0, -1, 1, 0, -1, 1, -1};
int CASE = 1;
int A[MAXN];
char S[MAXN];
struct Point {
    int X[2];
    Point() {}
    Point(int x, int y) { X[0] = x, X[1] = y; }
    bool operator<(const Point& a) const {
        return X[0] < a.X[0] || (X[0] == a.X[0] && X[1] < a.X[1]);
    }
};

void solve() {
    std::vector<Point> pts;
    for (int i = 0; i < 4; i++) {
        Point p;
        scanf("%d%d", &p.X[0], &p.X[1]);
        pts.push_back(p);
    }
    ll ans = INF64;
    for (int i = 0; i < 2; i++) {
        auto cmp = [=](const Point& a, const Point& b) {
            return a.X[i] < b.X[i] || (a.X[i] == b.X[i] && a.X[!i] < b.X[!i]);
        };
        std::sort(pts.begin(), pts.end(), cmp);
        for (int j = 0; j < 4; j++) {
            for (int k = i; k < 4; k++) {
                int len = std::abs(pts[j].X[i] - pts[k].X[i]);
                for (int s = 0; s < 4; s++) {
                    Point st;
                    st.X[i] = pts[j].X[i];
                    st.X[!i] = pts[s].X[!i];
                    for (int d = -1; d <= 1; d += 2) {
                        std::vector<Point> rect;
                        rect.push_back(Point(st.X[i], st.X[!i]));
                        rect.push_back(Point(st.X[i], st.X[!i] + d * len));
                        rect.push_back(Point(st.X[i] + len, st.X[!i]));
                        rect.push_back(
                            Point(st.X[i] + len, st.X[!i] + d * len));
                        std::sort(rect.begin(), rect.end());
                        do {
                            ll sum = 0;
                            for (int t = 0; t < 4; t++)
                                sum +=
                                    std::abs((ll)pts[t].X[i] - rect[t].X[0]) +
                                    std::abs((ll)pts[t].X[!i] - rect[t].X[1]);
                            ans = std::min(ans, sum);
                        } while (
                            std::next_permutation(rect.begin(), rect.end()));
                    }
                }
            }
        }
    }
    printf("%lld\n", ans);
}
int main() {
#ifdef LOCALLL
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    int T = read<int>();
    while (T--) solve();
    return 0;
}