#include<stdio.h> #define N 1000 #include<string.h> int result[N],map[N][N],vis[N],n,m; int dfs(int x) { int i; for(i=1;i<=m;i++) { if(!vis[i]&&map[x][i]) { vis[i]=1; if(result[i]==0||dfs(result[i])) { result[i]=x; return 1; } } } return 0; } int main() { int l,i,num,b; scanf("%d",&l); while(l--) { scanf("%d%d",&n,&m); memset(result,0,sizeof(result)); memset(map,0,sizeof(map)); //if(n!=m){printf("NO\n");continue;} for(i=1;i<=n;i++) { scanf("%d",&num); while(num--) { scanf("%d",&b); map[i][b]=1; } } int ans=0; for(i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); if(dfs(i))ans++; } if(ans==n)printf("YES\n"); else printf("NO\n"); } }