Program p1;
var x1,x2,x3,x4,y1,y2,y3,y4:real;
    kp,tkp,s:byte;
procedure vv;
begin
   read(x1,y1,x2,y2,x3,y3,x4,y4);
end;

procedure re;
 var c:real;
begin
   if x1>x2 then begin c:=x1; x1:=x2; x2:=c; end;
   if y1>y2 then begin c:=y1; y1:=y2; y2:=c; end;
   if x3>x4 then begin c:=x3; x3:=x4; x4:=c; end;
   if y3>y4 then begin c:=y3; y3:=y4; y4:=c; end;
   if (x1>x4)or(x2<x3)or(y1>y4)or(y2<y3)
      then s:=0
      else if ( (x1=x4)or(x2=x3) )and( (y1=y4)or(y2=y3) )
                then s:=1
                else if (x1=x4)or(x2=x3)or(y1=y4)or(y2=y3)
                       then s:=2
                       else s:=3;
end;

procedure viv;
begin
   write(s);
end;
Begin
    read(kp);
    for tkp:=1 to kp
       do begin
           vv;
           re;
           viv;
          end;
End.