#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;
bool flag;
int t,n,m;
int x,y;
int i,j,k,p;
int a[301][301];
int main()
{
freopen("line.in","r",stdin);
freopen("line.out","w",stdout);
scanf("%d",&t);
for (k=1;k<=t;k++)
{
flag=true;
scanf("%d%d",&n,&m);
for (i=1;i<=n;i++)
{
for (j=1;j<=n;j++)
{
a[i][j]=2;
}
}
for (i=1;i<=m;i++)
{
scanf("%d%d",&x,&y);
if (a[x][y]!=2)
{
flag=false;
goto fuck;
}
scanf("%d",&a[x][y]);
a[y][x]=a[x][y];
}
if (flag==true)
{
for (p=1;p<=n;p++)
for (i=1;i<=n;i++)
for (j=1;j<=n;j++)
{
if ((a[i][j]!=2)&&(a[i][p]!=2)&&(a[p][j]!=2))
{
if ((a[i][p]==a[p][j])&&(a[i][j]==1))
{
flag=false;
goto fuck;
}
if ((a[i][p]!=a[p][j])&&(a[i][j]==0))
{
flag=false;
goto fuck;
}
}
if ((a[i][j]==2)&&(a[i][p]!=2)&&(a[p][j]!=2))
{
if ((a[i][p]==0)&&(a[p][j]==0)) a[i][j]=0;
if ((a[i][p]==1)&&(a[p][j]==1)) a[i][j]=0;
if ((a[i][p]==1)&&(a[p][j]==0)) a[i][j]=1;
if ((a[i][p]==0)&&(a[p][j]==1)) a[i][j]=1;
}
}
}
fuck:
if (flag==false)
{
printf("No Answer\n");
}
else
{
printf("%d\n",a[1][n]);
}
}
}