program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var ij, ii,i,j:integer;

begin
 assign(input,'ROOK.IN'); reset(input);
 readln(ii);
 for ij := 1 to ii do begin
 readln(i,j);
 if (i=1) AND (j=1) then writeln('0') else
  begin
    if i=j then writeln('2') else writeln('1');
  end;

 end;
end.
