#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
#define N 500
int n1, n2, ans;
int result[N];
bool state[N];
bool map[N][N];
bool find(int x)
{
for (int i = ; i <= n2; ++i){
if (map[x][i] && !state[i]){
state[i] = true;
if (result[i] == || find(result[i])){
result[i] = x;
return true;
}
}
}
return false;
}
int hungary()
{
for (int i = ; i <= n1; ++i){
memset(state, , sizeof(state));
if (find(i)) ++ans;
}
return ans;
}
int main()
{
int t, p, n;
int a, b;
scanf("%d", &t);
while (t--){
memset(map, , sizeof(map));
memset(result, , sizeof(result));
ans = ;
scanf("%d %d", &p, &n);
for (int i = ; i <= p; ++i){
scanf("%d", &a);
for (int j = ; j <= a; ++j){
scanf("%d", &b);
map[i][b] = true;
}
}
n1 = p; n2 = n;
//cout << hungary() << endl;
if (p == hungary()) cout << "YES" << endl;
else cout << "NO" << endl;
}
}