#include <iostream>
#include <fstream>
using namespace std;
int t,i,j,k,l;
int o,p,q;
int n,m;
int a[301][301];
bool b;
int main()
{
ifstream fin("line.in");
ofstream fout("line.out");
fin>>t;
for (l=1;l<=t;l++)
{
b=false;
fin>>n>>m;
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
a[i][j]=2;
for (i=1;i<=m;i++)
{
fin>>o>>p>>q;
a[o][p]=q;
a[p][o]=q;
}
for (k=1;k<=n;k++)
{
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
if ((a[i][k]!=2)and(a[j][k]!=2))
if ((i!=k)and(j!=k)and(i!=j))
{
o=a[i][k] xor a[j][k];
if ((a[i][j]==2)or(a[i][j]==o))
{
a[i][j]=o;
}
else
{
fout<<"No Answer"<<endl;
b=true;
break;
}
}
}
if (b) break;
}
if (b) break;
}
if (not b)
fout<<a[1][n]<<endl;
}
fin.close();
fout.close();
return 0;
}