#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define vec vector
#define pii pair<int, int> 
using namespace std;

const long long MAXVAL = (long long) 1e18 + 1;
const long long MOD = 1000000007ll;
//const long long MOD = 998244353ll;
const int INF = 1000000001;

long long poww(int x, long long pow) {
  if (pow == 0ll ) return 1;
  if (pow == 1ll) return x % MOD;
  long long ans = poww(x, pow >> 1) % MOD;
  ans = (ans * ans) % MOD;
  if ((pow & 1) == 1) {
    ans = (ans * x ) % MOD;
  }
  return ans % MOD;
}

ll gcd(ll x, ll y) {
  if (x == 0) return y;
  while (y) {
    x %= y;
    swap(x, y);
  }
  return x;
}

ll sq(int x, int y){ 
  return x * 1ll * x + y  * 1ll * y;
}

//vector<int> pi(1000);
//vector<int> w(1000);

//int dsu_get(int x) {
  //if (pi[x] == x) return x;
  //int res = dsu_get(pi[x]);
  //pi[x] = res;
  //return res;
//}
//void dsu_merge(int x, int y) {
  //if (x == y) return;
  //x = dsu_get(x);
  //y = dsu_get(y);
  //if (x == y) return;
  //if (w[x] > w[y]) swap(x, y);
  //pi[y] = x;
  //w[y] += w[x];
//}

//struct intr {
  //int x, a, lb, rb;
  //intr(int x_, int a_, int lb_, int rb_) {
    //x = x_;
    //a = a_;
    //lb = lb_;
    //rb = rb_;
  //}
//};
//
//vec<int> t;

//void init (int nn) {
  //n = nn;
  //t.assign (n, 0);
//}

//int sum (int r) {
  //int result = 0;
  //for (; r >= 0; r = (r & (r+1)) - 1) result += t[r];
  //return result;
//}

//void inc (int i, int delta) {
  //for (; i < n; i = (i | (i+1))) t[i] += delta;
//}

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int q = 1;
  cin >> q;
  while (q-- > 0) { 
    pii pts[4];
    for (int i = 0; i < 4; ++i) {
      int x, y;
      cin >> x >> y;
      pts[i] = make_pair<>(x, y);
    }
    ll ans = (ll) 1e10;
    for (int ii = 0; ii < 4; ++ii) {
      for (int jj =0 ;jj < 4; ++jj) {
        int x0 = pts[ii].first;
        int y0 = pts[jj].second;
        do {
          auto fun = [&](ll L) {
            ll minans = (ll) 1e10;
            for (int i = -1; i <= 1; i += 2) {
              for (int j = -1 ;j <= 1; j +=2 ) {
                ll ans = 0ll;
                int sgnx = i;
                int sgny = j;
                for (int k = 0; k < 2; ++k) {
                  ans += abs(x0 - pts[k].first);
                }
                ans += abs(x0 + sgnx * L - pts[2].first);
                ans += abs(x0 + sgnx * L - pts[3].first);

                ans += abs(y0 - pts[0].second);
                ans += abs(y0 - pts[3].second);
                ans += abs(y0 + sgny * L - pts[1].second);
                ans += abs(y0 + sgny * L - pts[2].second);
                minans = min(minans, ans);
              }
            }
            return  minans;
          };
          ans = min(ans, fun(pts[2].first - x0));
          ans = min(ans, fun(pts[3].first - x0));
          ans = min(ans, fun(-pts[2].first + x0));
          ans = min(ans, fun(-pts[3].first + x0));

          ans = min(ans, fun(pts[1].second - y0));
          ans = min(ans, fun(pts[2].second - y0));
          ans = min(ans, fun(-pts[1].second + y0));
          ans = min(ans, fun(-pts[2].second + y0));
        } while (next_permutation(pts, pts + 4));
      }
    }
    cout << ans << "\n";
  }
  return 0;
}
