#include <iostream>
#include <cassert>
#include <complex>
#include <vector>
using namespace std;

//#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define P complex<double>
#define L vector<P>
#define pb push_back
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define y1 Y1

int N,x1,y1,x2,y2,X,Y;

double cross(const P &a,const P &b){
    return imag(conj(a)*b);
}

P crosspoint(const L &l, const L &m) {
    double A = cross(l[1] - l[0], m[1] - m[0]);
    double B = cross(l[1] - l[0], l[1] - m[0]);
    if (abs(A) < EPS && abs(B) < EPS) return m[0];
    if (abs(A) < EPS) assert(false);
    return m[0] + B / A * (m[1] - m[0]);
}

bool online(int x1,int y1,int x2,int y2){
    return x1==x2 || y1==y2 || abs(x1-x2)==abs(y1-y2);
}

int main(){
	cin>>N;
    rep(tc,N){
        cin>>x1>>y1>>x2>>y2>>X>>Y;
        
        if(x1==X && y1==Y || x2==X && y2==Y){
            cout<<0<<endl;
            continue;
        }
        
        if(online(x1,y1,X,Y) && online(x2,y2,X,Y)){
            cout<<1<<endl;
            continue;
        }
        
        if(online(x1,y1,X,Y) || online(x2,y2,X,Y)){
            cout<<2<<endl;
            continue;
        }
        
        if(online(x1,y1,x2,y2)){
            cout<<3<<endl;
            continue;
        }
        
        P a(x1,y1),b(x2,y2);
        L l[4],m[4];
        l[0].pb(a); l[0].pb(a+P(1,0));
        l[1].pb(a); l[1].pb(a+P(1,1));
        l[2].pb(a); l[2].pb(a+P(0,1));
        l[3].pb(a); l[3].pb(a+P(-1,1));
        m[0].pb(b); m[0].pb(b+P(1,0));
        m[1].pb(b); m[1].pb(b+P(1,1));
        m[2].pb(b); m[2].pb(b+P(0,1));
        m[3].pb(b); m[3].pb(b+P(-1,1));
        
        rep(i,4)rep(j,4)if(i!=j){
            P p=crosspoint(l[i],m[j]);
            double x=p.real(), y=p.imag();
            int xx=x+EPS, yy=y+EPS;
            if(x-xx > 0.4)continue;
            if(online(xx,yy,X,Y)){
                cout<<3<<endl;
                goto end;
            }
        }
        
        cout<<4<<endl;
    end:;
    }
}