#include <bits/stdc++.h>
#define rep(i,a,b) for(int i = (a); i <= (b); i++)
#define rng(a) a.begin(), a.end()
#define ina(n,a) cin >> n; for(int i = 1; i <= n; i++) cin >> a[i]
#define sz(x) (int)(x).size()
#define se second
#define fi first
#define prev            coyhhhhhhyoc    
#define next          sdNNNmNNNNNNNmds  
#define y0           hNNNNy_yNNNNNN_sNh
#define y1          mNNNNNdtdNNNNNNtsNNm
#define yn          mNNNNNNNNy___smNNNms
#define tm            oooooosyysooooot 
#define read               tyhyt        
#define rank              ytmNmo         
#define index              yyy
#define pb push_back
#define pcnt __builtin_popcountll
#define rrep(i,a,b) for(int i = (b); i >= (a); i--)
#define rall(x,a) for(auto x : a)
#define MOD 1000000007
#define endl "\n"
#define int long long
typedef long long ll;
using namespace std;

const int N = 5;
int x[N], y[N], ord[N];
int n = 4;

int dist(int l1, int r1, int l2, int r2) {
    if(l1 >= l2 && l1 <= r2) return 0;
    if(l2 >= l1 && l2 <= r1) return 0;
    return r1 < l2 ? l2 - r1 : l1 - r2;
}

int solve() {
    rep(i, 1, n) {
        cin >> x[i] >> y[i];
        ord[i] = i;
    }
    int ans = 1e18;
    do {
        int ax = x[ord[1]], bx = x[ord[2]], cx = x[ord[3]], dx = x[ord[4]];
        int ay = y[ord[1]], by = y[ord[2]], cy = y[ord[3]], dy = y[ord[4]];
        int cur = abs(ax - bx) + abs(cx - dx);
        int lx1 = min(ax, bx), rx1 = max(ax, bx);
        int lx2 = min(cx, dx), rx2 = max(cx, dx);
        int lx = dist(lx1, rx1, lx2, rx2), rx = max(abs(lx1 - rx2), abs(lx2 - rx1));

        cur += abs(ay - cy) + abs(by - dy);
        int ly1 = min(ay, cy), ry1 = max(ay, cy);
        int ly2 = min(by, dy), ry2 = max(by, dy);
        int ly = dist(ly1, ry1, ly2, ry2), ry = max(abs(ly1 - ry2), abs(ly2 - ry1));

        if(rx < ly) {
            cur += 2 * (ly - rx);
        } else if(ry < lx) {
            cur += 2 * (lx - ry);
        }
        ans = min(ans, cur);
    } while(next_permutation(ord + 1, ord + n + 1));
    cout << ans << endl;
    return 0;
}
 
signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int t;
    cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}
