program WEIGHING;
var a,k,n,i,j,l,m:longint;
 e:real;
input:text;
begin
     assign(input, 'ROOK.IN');
     reset(input);
     readln(input, a);
     for i:=1 to a do
     begin
     readln(input,n,m);
     if (m=1) and (n=1) then writeln('0') else if m=n then writeln('2') else writeln('1');
     end;

close(input);
end.