program Project1;

{$APPTYPE CONSOLE}

var
f:textfile;
r,n,i,rlt:integer;
x1,y1:REAL;
begin
assign(f, 'ROOK.IN');
reset(f);
readln(f,n);
for I := 1 to n do begin
    readln(F,x1,y1);
   if (X1=1) AND (Y1=1)  then BEGIN
     RLT:=0;
    END ELSE BEGIN
     if x1=y1 then begin
       rlt:=2;
      end else begin
       rlt:=1
      end;
    END;
    writeln(rlt);
end;
close(f);
end.

