#include<bits/stdc++.h>
#define fs first
#define sc second
using namespace std;
typedef long long ll;

const int INF = 1e9;
const int  kx[] = {0,1,1,-1}, ky[] = {1,0,1,1};

inline pair<int,int> line_cp(int d1, int x1, int y1, int d2, int x2, int y2){
  int X=INF, Y=INF;
  if(d1==d2)return make_pair(X,Y);

  if(kx[d1] == 0){
    if(kx[d2] != 0){
      Y = y1;
      X = ky[d2]*(Y-y2)/kx[d2] + x2;
    }
    return make_pair(X,Y);
  }
  if(ky[d1] == 0){
    if(ky[d2] != 0){
      X = x1;
      Y = kx[d2]*(X-x2)/ky[d2] + y2;
    }
    return make_pair(X,Y);
  }
  if(kx[d2] == 0){
    Y = y2;
    X = ky[d1]*(Y-y1)/kx[d1] + x1;
    return make_pair(X,Y);
  }
  if(ky[d2] == 0){
    X = x2;
    Y = kx[d1]*(X-x1)/ky[d1] + y1;
    return make_pair(X,Y);
  }

  int dy1 = ky[d1]*kx[d2], dy2 = ky[d2]*kx[d1];
  Y = (dy1*y1 - dy2*y2 - kx[d1]*kx[d2]*(x1-x2) );
  if(dy1-dy2==0 || abs(Y) % abs(dy1-dy2) != 0)return make_pair(INF,INF);
  Y /= dy1-dy2;
  X = ky[d1]*(Y-y1)/kx[d1] + x1;
  return make_pair(X,Y);
}

inline int check(int x1,int y1,int x2,int y2){
  int difx = abs(x1-x2), dify = abs(y1-y2);
  if( difx == dify || difx==0 || dify==0 )return 1;
  return 0;
}

inline int solve(int k){
  int x1,y1,x2,y2,X,Y;
  cin >> x1 >> y1 >> x2 >> y2 >> X >> Y;
  if( (x1==X && y1==Y) || (x2==X && y2==Y) )return 0;
  int cnt = check(x1,y1,X,Y) + check(x2,y2,X,Y);
  if(cnt)return 3-cnt;

  if(check(x1,y1,x2,y2))return 3;
  for(int d1=0;d1<4;d1++){
    for(int d2=0;d2<4;d2++){
      pair<int,int> p = line_cp(d1,x1,y1,d2,x2,y2);
      if(p.fs!=INF && check(p.fs, p.sc, X,Y))return 3;
    }
  }
  return 4;
}

int main(){
  int n; cin >> n;
  for(int i=1;i<=n;i++){
    cout << solve(i) << endl;
  }
}