#include<stdio.h>
#include<iostream>
using namespace std;
#define MAXN 305
int g[MAXN][MAXN];
int uN,vN;
int linker[MAXN];
bool used[MAXN];
bool dfs(int u)
{
int v;
for(v=1;v<=vN;v++)
if(g[u][v]&&!used[v])
{
used[v]=true;
if(linker[v]==-1||dfs(linker[v]))
{
linker[v]=u;
return true;
}
}
return false;
}
int hungary()
{
int res=0,u;
memset(linker,-1,sizeof(linker));
for(u=1;u<=uN;u++)
{
memset(used,0,sizeof(used));
if(dfs(u)) res++;
}
return res;
}
int main()
{
int u,v;
int T,i,n;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&uN,&vN);
memset(g,0,sizeof(g));
for(u=1;u<=uN;u++)
{
scanf("%d",&n);
while(n--)
{
scanf("%d",&v);
g[u][v]=1;
}
}
if(uN==hungary()) printf("YES\n");
else printf("NO\n");
}
return 0;
}