In 20XX, many years of research have paid off, and wireless energy transmission and reception technology has been put into practical use. By using this technology, it has become possible to supply power to depopulated areas where it was not possible to draw power lines because the cost was not worth it. This technology has some quirks and can send energy as far as it can go, but it has the limitation that it can only receive radio waves at specific locations. In other words, if the world is represented by a two-dimensional plane, the positive direction of the y-axis is north, and the positive direction of the x-axis is east, radio waves can be received only at points where both the x-coordinate and y-coordinate are integers (phase). It's a problem). In addition, radio waves can only be transmitted in eight directions (east, west, south, north, northeast, northwest, southeast, and southwest) when viewed from the base (equipment capable of transmitting and receiving radio waves).

Due to this restriction, it may not be possible to directly supply radio waves to the target location, but this can be solved by setting up a relay station. For example, energy cannot be sent directly from coordinates (0, 0) to (3, 7), but this can be solved by placing a relay station at (3, 3).

You are an engineer at an electric power company, and a customer asks you to set up a base in a certain place. However, in order to avoid the problem that the power stops just because a certain part breaks down, when laying a new base, it is necessary to receive energy from two or more bases that have already been built. Also, only one base can be built at a time, and two bases cannot be placed in the same location. Given two existing base locations, ask for at least how many more bases need to be built to meet customer demand.



Input

The input consists of multiple datasets.

The first line of input is given the number of datasets N (0 <N ≤ 300). Each dataset is given in the following N lines.

One dataset consists of one line of strings, given six integers separated by spaces as shown below.

x1 y1 x2 y2 X Y

(x1, y1) and (x2, y2) are the coordinates of the two existing bases, and (X, Y) are the coordinates of the destination. The x, y coordinate values ​​given by the input satisfy -100000000 ≤ x, y ≤ 100000000. The coordinates of the two existing bases are guaranteed to be different.

Output

For each dataset, output the number of bases that need to be laid in one line.

Example

Input

4
0 1 3 2 0 1
1 1 2 2 9 9
0 0 1 4 5 5
0 0 1 4 5 10


Output

0
1
2
3
#include<bits/stdc++.h>

#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define EPS (1e-5)
#define equals(a,b) (fabs((a)-(b)) < EPS)
#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1 
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0

using namespace std;

class Point{
public:
  double x,y;

  Point(double x = 0,double y = 0): x(x),y(y){}

  Point operator + (Point p){return Point(x+p.x,y+p.y);}
  Point operator - (Point p){return Point(x-p.x,y-p.y);}
  Point operator * (double a){return Point(a*x,a*y);}
  Point operator / (double a){return Point(x/a,y/a);}
  Point operator * (Point a){ return Point(x * a.x - y * a.y, x * a.y + y * a.x); }

  bool operator < (const Point& p) const{ return !equals(x,p.x)?x<p.x:(!equals(y,p.y)&&y<p.y); }

  bool operator == (const Point& p)const{ return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS; }

};

struct Segment{
  Point p1,p2;
  Segment(Point p1 = Point(),Point p2 = Point()):p1(p1),p2(p2){}
  bool operator <  (const Segment& s) const { return ( p2 == s.p2 ) ? p1 < s.p1 : p2 < s.p2; }
  bool operator == (const Segment& s) const { return ( s.p1 == p1 && s.p2 == p2 ) || ( s.p1 == p2 && s.p2 == p1 ); }

};

typedef Point Vector;
typedef Segment Line;

ostream& operator << (ostream& os,const Point& a){ os << "(" << a.x << "," << a.y << ")"; }

ostream& operator << (ostream& os,const Segment& a){ os << "( " << a.p1 << " , " << a.p2 << " )"; }

double dot(Point a,Point b){ return a.x*b.x + a.y*b.y; }

double cross(Point a,Point b){ return a.x*b.y - a.y*b.x; }

double norm(Point a){ return a.x*a.x+a.y*a.y; }

double abs(Point a){ return sqrt(norm(a)); }

int ccw(Point p0,Point p1,Point p2){
  Point a = p1-p0;
  Point b = p2-p0;
  if(cross(a,b) > EPS)return COUNTER_CLOCKWISE;
  if(cross(a,b) < -EPS)return CLOCKWISE;
  if(dot(a,b) < -EPS)return ONLINE_BACK;
  if(norm(a) < norm(b))return ONLINE_FRONT;
  return ON_SEGMENT;
}

bool intersectLL(Line l, Line m) {
  return abs(cross(l.p2-l.p1, m.p2-m.p1)) > EPS || // non-parallel
         abs(cross(l.p2-l.p1, m.p1-l.p1)) < EPS;   // same line
}
bool intersectLS(Line l, Line s) {
  return cross(l.p2-l.p1, s.p1-l.p1)*       // s[0] is left of l
         cross(l.p2-l.p1, s.p2-l.p1) < EPS; // s[1] is right of l
}
bool intersectLP(Line l,Point p) {
  return abs(cross(l.p2-p, l.p1-p)) < EPS;
}
bool intersectSS(Line s, Line t) {
  return ccw(s.p1,s.p2,t.p1)*ccw(s.p1,s.p2,t.p2) <= 0 &&
         ccw(t.p1,t.p2,s.p1)*ccw(t.p1,t.p2,s.p2) <= 0;
}
bool intersectSP(Line s, Point p) {
  return abs(s.p1-p)+abs(s.p2-p)-abs(s.p2-s.p1) < EPS; // triangle inequality
}

Point projection(Line l,Point p) {
  double t = dot(p-l.p1, l.p1-l.p2) / norm(l.p1-l.p2);
  return l.p1 + (l.p1-l.p2)*t;
}
Point reflection(Line l,Point p) {
  return p + (projection(l, p) - p) * 2;
}
double distanceLP(Line l, Point p) {
  return abs(p - projection(l, p));
}
double distanceLL(Line l, Line m) {
  return intersectLL(l, m) ? 0 : distanceLP(l, m.p1);
}

double distanceLS(Line l, Line s) {
  if (intersectLS(l, s)) return 0;
  return min(distanceLP(l, s.p1), distanceLP(l, s.p2));
}
double distanceSP(Line s, Point p) {
  Point r = projection(s, p);
  if (intersectSP(s, r)) return abs(r - p);
  return min(abs(s.p1 - p), abs(s.p2 - p));
}

double distanceSS(Line s, Line t) {
  if (intersectSS(s, t)) return 0;
  return min(min(distanceSP(s, t.p1), distanceSP(s, t.p2)),
             min(distanceSP(t, s.p1), distanceSP(t, s.p2)));
}

Point crosspoint(Line l,Line m){
  double A = cross(l.p2-l.p1,m.p2-m.p1);
  double B = cross(l.p2-l.p1,l.p2-m.p1);
  if(abs(A) < EPS && abs(B) < EPS){
    vector<Point> vec;
    vec.push_back(l.p1),vec.push_back(l.p2),vec.push_back(m.p1),vec.push_back(m.p2);
    sort(vec.begin(),vec.end());
    assert(vec[1] == vec[2]); //テ・ツ青古」ツ?佚」ツつサテ」ツつーテ」ツδ。テ」ツδウテ」ツδ暗」ツ?凝」ツつづ」ツつ?
    return vec[1];
    //return m.p1;
  }
  if(abs(A) < EPS)assert(false);
  return m.p1 + (m.p2-m.p1)*(B/A);
}


double x[3],y[3];
int limit;

void compute(){
  rep(i,2) if( x[i] == x[2] && y[i] == y[2] ) { puts("0"); return; }
  int mini = 4;
  Point p = Point(x[2],y[2]);
  REP(dx1,-1,2){
    REP(dy1,-1,2){
      if( dx1 == dy1 && dx1 == 0 ) continue;
      Line l1 = Line(Point(x[0],y[0]),Point(x[0]+dx1,y[0]+dy1));
      REP(dx2,-1,2){
        REP(dy2,-1,2){
          if( dx2 == dy2 && dx2 == 0 ) continue;
          Line l2 = Line(Point(x[1],y[1]),Point(x[1]+dx2,y[1]+dy2));

          if( equals(cross(l1.p1-l1.p2,l2.p1-l2.p2),0.0) && intersectLP(l1,l2.p1) ) mini = min(mini,3);
          if( intersectLP(l1,p) && intersectLP(l2,p) ) { mini = 1; goto Fin; }
          if( intersectLP(l1,p) || intersectLP(l2,p) ) mini = 2;
          if( mini == 4 ) {
            if( equals(cross(l1.p1-l1.p2,l2.p1-l2.p2),0.0) ) continue;
            Point cp = crosspoint(l1,l2);
            if( equals(cp.x,(int)floor(cp.x+EPS)) && equals(cp.y,(int)floor(cp.y+EPS)) ) {
              REP(dx3,-1,2){
                REP(dy3,-1,2){
                  if( dx3 == dy3 && dx3 == 0 ) continue;
                  Line l3 = Line(cp,Point(cp.x+dx3,cp.y+dy3));
                  if( intersectLP(l3,p) ) { mini = min(mini,3); goto Skip; }
                }
              }
            Skip:;
            }
          }
        }
      }
    }
  }
  Fin:;
  printf("%d\n",mini);
}

int main(){
  int T;
  cin >> T;
  while( T-- ) {
    rep(i,3) cin >> x[i] >> y[i];
    compute();
  }
  return 0;
}