var N,i,T,M: longint;
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 M=N then writeln(2) else write(1);
end;
end.
