#include #include #include #include #include #include #include using namespace std; #define ll long long const double eps=1e-8; const ll inf=1e9; const ll mod=1e9+7; const int maxn=1e5+10; int f[60][60],g[60][60],v[60],cond,m; char a[60],b[60],rest[60]; bool z[60][60],vis[60]; void dfs(int i) { if (i==m) { cond=1; return; } bool c; int j,k,l; for (j=1;j<=f[i][0];j++) if (!cond && !vis[f[i][j]]) { c=0; l=f[i][j]; vis[l]=1; for (k=1;k<=g[l][0];k++) { rest[g[l][k]]--; if (g[l][k]>i && rest[g[l][k]]==0) c=1; } if (!c) { v[i]=l; dfs(i+1); } vis[l]=0; for (k=1;k<=g[l][0];k++) rest[g[l][k]]--; } } int main() { int t,i,j,k,n,wrong; scanf("%d",&t); while (t--) { memset(z,0,sizeof(z)); scanf("%d%d",&n,&m); wrong=0; for (i=1;i<=n;i++) { scanf("%s%s",a,b); for (j=0;j