program line;
var
t,n,m,i,j,k,l,r,p:longint;
g:array[1..300,1..300] of longint;
bool:boolean;
begin
assign(input,'line.in');
assign(output,'line.out');
reset(input);
rewrite(output);
readln(t);
for l:=1 to t do
begin
bool:=true;
readln(n,m);
for i:=1 to n do
for j:=1 to n do
begin
g[i,j]:=2;
end;
for r:=1 to m do
begin
readln(i,j,k);
g[i,j]:=k;
g[j,i]:=k;
end;
for k:=1 to n do
for i:=1 to n do
for j:=1 to n do
if g[i][j]=2 then
begin
if (g[i][k]<>2) and (g[k][j]<>2) then g[i][j]:=g[i][k] xor g[k][j];
end
else
if (g[i][k]<>2) and (g[k][j]<>2) then
if g[i][j]<>g[i][k] xor g[k][j] then bool:=false;
if bool=false then writeln('No Answer')
else writeln(g[1,n]);
end;
close(input);
close(output);
end.