#include <bits/stdc++.h>
#define pb push_back
#define pp pop_back
#define rs resize
#define sz size
#define eb emplace_back
#define bk back
#define clr clear
#define fi first
#define se second
#define V vector
#define _for(i,a,b) for(int i = (a); i < (b); i++)
#define _rfr(i,a,b) for(int i=(a-1); i >= (b); i--)
#define _rep(i,a,b) for(int i = (a); i <=(b); i++)
#define _rrp(i,a,b) for(int i = (a); i >=(b); i--)
#define FOR(i,a)    for(int i = 0; i < (a); i++)
#define RFR(i,a)    for(int i=(a-1); i>= 0; i--)
#define REP(i,a)    for(int i = 1; i <=(a); i++)
#define RRP(i,a)    for(int i = (a); i >=1; i--)
#define TRAV(i,a)    for(int i = (0); i <=(b); i++)
#define each(i, x)  for(auto& i : x)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll , ll >;
using vi = vector<int>;
using vl = vector<ll>;
using vp = V<pi>;
using vpl = V<pl>;
using vvi = vector<vector<int>>;
const char nl = '\n';

template<typename... Args> void rd(Args&... args) { ((cin  >> args), ...); }
void wt() { cout << endl; }
template<typename Head, typename... Tail> void wt(Head H, Tail... T) { cout << H << ' '; wt(T...); }
void db() { cerr << endl; }
template<typename Head, typename... Tail> void db(Head H, Tail... T) { cerr << H << ' '; db(T...); }
template<typename T> void write(T v, int a = -1, int b = -1) {
  if (a == -1) a = 0, b = size(v);
  else if (b == -1) b = a, a = 0;
  _for(i, a, b) cout << v[i] << ' ';
  cout << '\n';
}
template<typename T> void dbg(T v, int a = -1, int b = -1) {
  if (a == -1) a = 0, b = size(v);
  else if (b == -1) b = a, a = 0;
  _for(i, a, b) cerr << v[i] << ' ';
  cerr << '\n';
}
template<typename T> void read(T& v, int a = -1, int b = -1) {
  if (a == -1) a = 0, b = size(v);
  else if (b == -1) b = a, a = 0;
  _for(i, a, b) cin >> v[i];
}
template<class T> bool uim(T& a, const T& b) {
  return b<a?a=b, 1:0;
}
template<class T> bool uax(T& a, const T& b) { 
  return a<b?a=b, 1:0;
} 


#define x fi
#define y se
#define l fi
#define r se

pl seg(ll a,ll b){ return {min(a,b),max(a,b)}; }
ll min_d(pl a,pl b){ return max(max(a.l,b.l)-min(a.r,b.r),0ll); }
ll max_d(pl a,pl b){ return max(a.r-b.l,b.r-a.l); }
pl range_d(pl a,pl b){ return {min_d(a,b),max_d(a,b)}; }
ll len(pl seg){ return seg.r-seg.l; }

void solve() {
  vpl p(4);
  FOR(i,4)rd(p[i].x,p[i].y);
  sort(all(p));
  ll ans=INT64_MAX;
  do {
    pl x1=seg(p[0].x,p[1].x),x2=seg(p[2].x,p[3].x);
    pl y1=seg(p[0].y,p[2].y),y2=seg(p[1].y,p[3].y);
    // db("x seg",x1.l,x1.r,x2.l,x2.r);
    pl rx=range_d(x1,x2),ry=range_d(y1,y2);
    // db("range",rx.l,rx.r,ry.l,ry.r);
    // db(len(x1),len(x2),len(y1),len(y2),min_d(rx,ry));
    ll cur=len(x1)+len(x2)+len(y1)+len(y2)+2*min_d(rx,ry);
    uim(ans,cur);
  } while (next_permutation(all(p)));
  wt(ans);
}

int main() {
  int T; cin >> T; while (T--) 
  solve();
  return 0;
}

