#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
const int MAXN = 2e5;
int match[MAXN], st[MAXN];
int n,m,p;
int e[MAXN],ne[MAXN],idx,h[MAXN];
void add(int a,int b)
{
e[idx]=b;
ne[idx]=h[a];
h[a]=idx++;
}
bool find(int x)
{
for (int i = h[x];i!=-1;i=ne[i])
{
int j = e[i];
if (st[j])
continue;
st[j] = 1;
if (match[j] == -1 || find(match[j]))
{
match[j] = x;
return true;
}
}
return false;
}
int Solve()
{
int cnt = 0;
memset(match, -1, sizeof(match));
for (int i = 1;i <= p;i++)
{
memset(st, 0, sizeof(st));
if (find(i))
cnt++;
}
return cnt;
}
int main()
{
int t;
cin >> t;
while (t--)
{
idx=0;
memset(h,-1,sizeof h);
cin >> p >> n;
if (p > n)
{
cout << "NO" << endl;
continue;
}
for (int i = 1;i <= p;i++)
{
int num, v;
cin >> num;
while (num--)
{
cin >> v;
add(i,v);
}
}
int cnt = Solve();
if (cnt < p)
cout << "NO" << endl;
else
cout << "YES" << endl;
}
return 0;
}