{$APPTYPE CONSOLE}
var t,i,n,m:integer;
begin
  assign(input, 'ROOK.IN'); reset(input);
  readln(t);
  for i:=1 to t do
  begin
   readln(n,m);
   if (n=1) and (m=1) then writeln(0)
                      else
   if n=m then writeln(2) else writeln(1);
  end;
end.