#include<iostream> #include<cstdio> #include<cstring> using namespace std; int map[305][305]; int vis[305]; int link1[305]; int link2[305],p,n; int dfs(int i) { int j; for(j=1;j<=n;j++) { if(map[i][j]&&!vis[j]) { vis[j]=1; if(link1[j]==-1||dfs(link1[j])) { link1[j]=i; link2[i]=j; return 1; } } } return 0; } int main() { int t; scanf("%d",&t); while(t--) { scanf("%d%d",&p,&n); int i,k,m; memset(map,0,sizeof(map)); for(i=1;i<=p;i++) { scanf("%d",&m); int j; for(j=0;j<m;j++) { scanf("%d",&k); map[i][k]=1; } } int s=0; memset(link1,-1,sizeof(link1)); memset(link2,-1,sizeof(link2)); for(i=1;i<=p;i++) { memset(vis,0,sizeof(vis)); dfs(i); } for(i=1;i<=p;i++) { if(link2[i]==-1) break; } if(i>p) printf("YES\n"); else printf("NO\n"); } }