program ROOK;

{$APPTYPE CONSOLE}

uses
  SysUtils;

var
   m,n,k,t,i:integer;

begin
assignfile(input,'ROOK.IN');
reset(input);
readln(t);
for i:=1 to t do begin
read(n,m);
if (n=m) and (n=1) then writeln('0')
else
if (n=1) or (m=1) then writeln('1')
else
writeln('0');

end;
  close(input);
end.
