program ROOK;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
  x,y,i,t:integer;

begin
  reset(input,'ROOK.IN');
 // rewrite(output,'output.txt');

  readln(t);

  for i := 1 to t do begin


    readln(x,y);
    if (x=1)and(y=1) then writeln('0') else if x=y then writeln(2) else writeln(1);
                                            


   { if (x=1) or (y=1) then  writeln(1) else begin


    x:=y+x-4;
    if(x mod 2) = 0 then writeln(2)
    else writeln(1);
    end;

    end;}





  end;


end.
