
{$APPTYPE CONSOLE}
var tests, i, x,y,win : integer;
begin
  assign(input, 'ROOK.IN'); reset(input);
  read(tests);
  for i := 1 to tests do
  begin
     read(x,y);
     if (x=1) and (y=1) then
         win:=0
     else
      begin
        if (x>1) and (y>1) then
          win:=2
        else
          win:=1;
     end;
     writeln(win);
  end;
  
end.
