{$APPTYPE CONSOLE}
var N,i,T,M,Q: 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 Q:=0;
If (N<>1) and (M=1) then Q:=1;
if (N=1) and (M=1) then Q:=0;
If (N=1) and (M<>1) then Q:=1;
writeln(Q);
dec(n);
end;
end.


