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);
n:=n-1;
m:=m-1;
n:=n+m;
if (n mod 2=0) and (n>0) then writeln('2');
if n mod 2<>0 then writeln('1');
if n=0 then writeln('0')
end;
end.