#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define sz(a) ((int)(a).size())
#define For(i, a, n) for(int i = a; i <= n; i++)
#define rof(i, n, a) for(int i = n; i >= a; i--)
#define endl "\n"
using namespace std;
const int maxn = 1e5 + 5;
int T;
int n, m, p, x, ans;
void solve()
{
cin >> n >> m;
vector<int> a(maxn);
set<int> g[maxn];
vector<set<int>> s(n+1);
ans = 0;
For(i, 1, n)
{
cin >> p;
For(j, 1, p)
{
cin >> x;
a[x] = i;
g[i].insert(x);
}
}
For(i, 1, m)
{
if(a[i] > 1 && g[a[i] - 1].count(i))
{
v[a[i]] = true;
}
}
For(i, 2, n)
{
if(!v[i])
{
ans = i;
break;
}
}
if(ans)
{
cout << "Yes" << endl;
For(i, 1, n)
{
if(i == ans - 1) cout << ans;
else if(i == ans) cout << ans - 1;
else cout << i;
cout << (i == n ? "\n" : " ");
}
}
else cout << "No" << endl;
return;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> T;
//T = 1;
For(I, 1, T)
{
solve();
}
return 0;
}