#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <stack>
template <class T, size_t size = std::tuple_size<T>::value> std::string to_debug(T, std::string s = "") requires(not std::ranges::range<T>);
std::string to_debug(auto x) requires requires(std::ostream& os) { os << x; } { return static_cast<std::ostringstream>(std::ostringstream() << x).str(); }
std::string to_debug(std::ranges::range auto x, std::string s = "") requires(not std::is_same_v<decltype(x), std::string>) {
for (auto xi : x) { s += ", " + to_debug(xi); }
return "[" + s.substr(s.empty() ? 0 : 2) + "]";
}
template <class T, size_t size> std::string to_debug(T x, std::string s) requires(not std::ranges::range<T>) {
[&]<size_t... I>(std::index_sequence<I...>) { ((s += ", " + to_debug(get<I>(x))), ...); }(std::make_index_sequence<size>());
return "(" + s.substr(s.empty() ? 0 : 2) + ")";
}
#ifndef ONLINE_JUDGE
#define debug(...) std::cerr << __LINE__ << ": (" #__VA_ARGS__ ") = " << to_debug(std::tuple(__VA_ARGS__)) << "\n"
#else
#define debug(x...)
#endif
using i64 = long long;
const int mxn = 1e6+6;
int mx[mxn];
int cnt[mxn];
bool del[mxn];
std::vector <int> p1;
std::set <int> p2;
void solve()
{
#define tests
int n, m;
std::cin >> n >> m;
p1.clear();
p2.clear();
for(int i = 1 ; i <= m ; i++){
mx[i] = cnt[i] = 0;
}
for(int pi, i = 1 ; i <= n ; i++){
del[i] = false;
std::cin >> pi;
for(int inp, j = 1 ; j <= pi ; j++){
std::cin >> inp;
mx[inp] = i;
cnt[inp]++;
}
}
for(int i = 1 ; i <= m ; i++){
if(cnt[i] >= 2){
p2.insert(mx[i]);
del[mx[i]] = true;
}
}
//debug(p1);
for(int i = 1 ; i <= n ; i++){
if(!del[i]){
p1.push_back(i);
}
}
//debug(p1);
if(p1.size() >= 2){
std::swap(p1[0], p1[1]);
std::cout << "Yes\n";
std::vector <int> ans;
for(auto x : p1)
ans.push_back(x);
for(auto x : p2)
ans.push_back(x);
for(int i = 0 ; i < n - 1 ; i++)
std::cout << ans[i] << " ";
std::cout << ans[n - 1] << "\n";
}else{
//std::cout << "No\n";
if(p1.size() == 1 ){
std::cout << "Yes\n";
std::vector <int> ans;
for(auto x : p1)
ans.push_back(x);
for(auto x : p2)
ans.push_back(x);
for(int i = 0 ; i < n - 1 ; i++)
std::cout << ans[i] << " ";
std::cout << ans[n - 1] << "\n";
}else{
std::cout << "No\n";
}
}
}
signed main()
{
std::cin.tie(nullptr)->sync_with_stdio(false);
int _{1};
#ifdef tests
std::cin >> _;
#endif
while(_--) solve();
return 0;
}