var
t,i,n,m:longint;
begin
assign (input,'rook.in'); reset (input);
readln (t);
for i:=1 to t do begin
readln (n,m);
if (n=m) and (n>1) then writeln('2') else
if (n=m) and (n=1) then writeln('0') else
   writeln('1');
end;
end.