program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var T,N,M,i:longint;

f1 : text;

begin
Assign(f1, 'ROOK.IN');
reset(f1);
readln(f1,T);
for i := 1 to T do begin readln(f1,N,M);
  if (N = M) and (N<>1) then writeln(2);
  if  (N=M) and (N=1) then writeln(0);
  if (N<>M)  then writeln(1);

end;




end.
