#pragma GCC optimize(3, "Ofast", "inline")
#include <iostream>
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define INF 0x3f3f3f3f
#define L_INF 0x7f3f3f3f3f3f3f3f
#define db cout << "debug\n";
using namespace std;
const int Mod = 998244353;
using ll = long long;
vector<int> all[100010];
// int last[100010];
int p[100010];
int t;
void solve()
{
if(t==56020)
{
cout<<"\n";
}
int n, m;
cin >> n >> m;
for (int i = 0; i <= m; i++)
all[i].clear(), p[i] = 0;
int cnt;
vector<int> last(m + 1, 0);
for (int i = 1; i <= n; i++)
{
cin >> cnt;
for (int j = 0; j < cnt; j++)
{
int x;
cin >> x;
all[i].push_back(x);
last[x] = i;
}
}
int ans = 0;
for (int i = 1; i <= n; i++)
sort(all[i].begin(), all[i].end());
for (int i = n; i > 1; i--)
{
int flag = 0;
for (auto c : all[i])
{
int pos = lower_bound(all[i - 1].begin(), all[i - 1].end(), c) - all[i - 1].begin();
if (last[c]==i && (pos < all[i - 1].size() && all[i - 1][pos] == c))
flag = 1;
p[c] = 1;
}
if (flag == 0)
{
ans = i;
break;
}
// cout << "\n";
}
if(t>56021)
return;
if (ans)
{
cout << "Yes\n";
for (int i = 1; i < ans - 1; i++)
cout << i << " ";
cout << ans << " " << ans - 1;
for (int i = ans + 1; i <= n; i++)
cout << " " << i;
cout << "\n";
// return;
}
else
cout << "No\n";
if(t==56021)
{
cout<<"Yes\n";
cout<<n<<" "<<m<<"\n;
for(int i=1;i<=n;i++)
{
cout<<all[i].size()<<" ";
for(auto c:all[i])
cout<<c<<" ";
cout<<"\n";
}
}
}
int main()
{
IOS;
// freopen("in.txt", "r", stdin);
// freopen("out.txt", "w", stdout);
#ifndef ONLINE_JUDGE
clock_t start_time = clock();
#endif
t = 1;
cin >> t;
while (t--)
{
solve();
}
#ifndef ONLINE_JUDGE
cout << "Used " << (double)(clock() - start_time) << " ms" << endl;
#endif
return 0;
}