// #pragma GCC optimize("no-stack-protector") // #pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx,tune=native") // #pragma GCC diagnostic ignored "-W" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #if __cplusplus >= 201103L #include #include #include #endif // #include // #include // #include using namespace std; // using namespace __gnu_pbds; #define ll long long #define ld long double #define X first #define Y second #define pb push_back #define eb emplace_back #define pii pair #define vint vector #define vpii vector> #define SS stringstream #define PQ priority_queue #define MS(x, v) memset((x), (v), sizeof(x)) #define RZUNI(x) sort(x.begin(), x.end()), x.resize(unique(x.begin(), x.end()) - x.begin()) #define FLH fflush(stdout) #define CPPinput ios_base::sync_with_stdio(0), cin.tie(0) #define FIO(fname) freopen(fname ".in", "r", stdin), freopen(fname ".out", "w", stdout) #define FIN(fname) freopen(fname, "r", stdin) #define FOUT(fname) freopen(fname, "w", stdout) #define tm Ovuvuevuevue #define y1 Enyetuenwuevue #define left Ugbemugbem #define ws Osas #define dec tetteterette #define expl explexplexpl #define data datadetedoto #define YES cout << "YES" << endl #define NO cout << "NO" << endl #define Yes cout << "Yes" << endl #define No cout << "No" << endl #ifdef WEAK #include"/home/edison/Coding/cpp/template/debug.cpp" #define DEB(...) printf(__VA_ARGS__), fflush(stdout) #define WHR() printf("%s: Line %d", __PRETTY_FUNCTION__, __LINE__), fflush(stdout) #define LOG(...) printf("%s: Line %d ", __PRETTY_FUNCTION__, __LINE__), printf(__VA_ARGS__), fflush(stdout) #define DEBUG 1 #define exit(x) cout << "exit code " << x << endl, exit(0) #else #define PDE(...) ; #define DEB(...) ; #define WHR() ; #define LOG(...) ; #define DEBUG 0 #endif #define lowbit(x) ((x) & (-(x))) void JIZZ(string output = ""){ cout << output; exit(0); } const long double PI = 3.14159265358979323846264338327950288; const long double eps = 1e-10; const long long mod = 1e9+7; void solve() { int n; cin >> n; vector>> rd(n); vector vir(n, 0); vir[0] = 1; for (int i = 0; i < n; ++i) { int s; cin >> s; while (s--) { int t, p; cin >> t >> p; --p; rd[i].emplace_back(t, p); } } for (int i = 1; i <= 100; ++i) { vector> at(10); vector _vir(10, 0); for (int j = 0; j < n; ++j) if (rd[j].size() && rd[j][0].first == i) { at[rd[j][0].second].push_back(j); if (vir[j]) _vir[rd[j][0].second] = 1; rd[j].pop_front(); } for (int j = 0; j < 10; ++j) if (_vir[j]) { for (int k : at[j]) vir[k] = 1; } } vector z; for (int i = 0; i < n; ++i) if (vir[i]) z.push_back(i + 1); for (int i = 0; i < (int)z.size(); ++i) cout << z[i] << " \n"[i == (int)z.size() - 1]; } int main() { CPPinput; int t; cin >> t; while (t--) solve(); }