#pragma GCC optimize("O3")
#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;

//template<class T> using oset=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
//template<class T> using omultiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;

//find_by_order
//order_of_key

#define x first
#define y second
#define pb push_back
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<pii> vii;
typedef vector<pll> vll;

mt19937 rnd(time(nullptr));

pll a[10], p[10];


ll check(ll n) {
    for (int i=1; i<=4; ++i)
        a[i]=p[i];
    ll res1=0, res2=0;

    ll d1=0, d2=0;
    d1=a[1].x+n-a[2].x;
    res1+=abs(d1);
    a[2].x=a[1].x+n;

    d2=a[3].x+n-a[4].x;
    res1+=abs(d2);
    a[4].x=a[3].x+n;

    ll need=a[3].x-a[1].x;
    if (need > 0 && d2 > 0) {
        ll mn=min(need, d2);
        need-=mn;
    }
    if (need > 0 && d1 < 0) {
        ll mn=min(need, -d1);
        need-=mn;
    }
    if (need < 0 && d2 < 0) {
        ll mn=min(-need, -d2);
        need+=mn;
    }
    if (need < 0 && d1 > 0) {
        ll mn=min(-need, d1);
        need+=mn;
    }
    res1+=2*abs(need);

    d1=0, d2=0;
    d1=a[2].y+n-a[4].y;
    res2+=abs(d1);
    a[4].y=a[2].y+n;

    d2=a[1].y+n-a[3].y;
    res2+=abs(d2);
    a[3].y=a[1].y+n;

    need=a[1].y-a[2].y;
    if (need > 0 && d2 > 0) {
        ll mn=min(need, d2);
        need-=mn;
    }
    if (need > 0 && d1 < 0) {
        ll mn=min(need, -d1);
        need-=mn;
    }
    if (need < 0 && d2 < 0) {
        ll mn=min(-need, -d2);
        need+=mn;
    }
    if (need < 0 && d1 > 0) {
        ll mn=min(-need, d1);
        need+=mn;
    }
    res2+=2*abs(need);

    return res1+res2;
}


void solve() {
    for (int i=1; i<=4; ++i)
        cin >> p[i].x >> p[i].y;
    ll ans=1e15;
    sort(p+1, p+5);
    do {
        int l=0, r=1e9+5;
        while(l+5 < r) {
            int m1=l+(r-l)/3, m2=r-(r-l)/3;
            if (check(m1) < check(m2))
                r=m2;
            else
                l=m1;
        }
        for (int i=l; i<=r; ++i)
            ans=min(ans, check(i));
    } while(next_permutation(p+1, p+5));
    cout << ans << "\n";
}




int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t; cin >> t;
    while(t--) solve();
}

