
{$APPTYPE CONSOLE}
var f:text;
N,i,T,M: longint;
begin
assignFile(f, 'ROOK.IN');
reset(f);
readln(f, T);
for i:=1 to T do
begin
readln(f, N,M);
if (N=1) and (M=1) then writeln(0) else
if M=N then writeln(2) else write(1);
end;
end.

