program rook;

{$APPTYPE CONSOLE}

Var n,m,t,i: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 (n+m) mod 2=0 then Writeln('2')
  else Write('1');
end;
end.
