#ifdef LOCAL #include #else #include #include #include #endif #define lp(i, l, r) for (auto i = regu(l); i <= decltype(i)(r); ++i) #define rp(i, r, l) for (auto i = regu(r); i >= decltype(i)(l); --i) #define lv(i, a) for (int i = 0; i < int(a.size()); ++i) #define rv(i, a) for (int i = int(a.size()) - 1; i >= 0; --i) #define lm(i, m) for (auto i = m; i; i = (m) & (i - 1)) #define many for (int C = 1, T = -1; T < 0 && cin >> T, C <= T; ++C) #define goog "Case #" + to_string(C) + ":" #define rang(a) begin(a), end(a) #define elif else if #ifndef LOCAL #define endl '\n' #undef assert #define assert #endif using namespace std; using namespace __gnu_pbds; const auto eps = 1e-8, pi = acos(-1); template int comp(const T &a, const T &b) { return a < b - eps ? -1 : (a > b + eps); } #if __cplusplus > 201103L template auto regu(const T &a) { return int(a); } template <> auto regu(const int64_t &a) { return a; } template <> auto regu(const uint64_t &a) { return int64_t(a); } #else template int64_t regu(const T &a) { return int(a); } template <> int64_t regu(const int64_t &a) { return a; } template <> int64_t regu(const uint64_t &a) { return a; } #endif template int barr(const T &a, const int &i) { return int(a >> i & 1); } template int bcnt(const T &a) { return __builtin_popcount(a); } template <> int bcnt(const int64_t &a) { return __builtin_popcountll(a); } template int blen(const T &a) { return a ? 1 + blen(a / 2) : 0; } mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); template T rint(T l, T r) { return uniform_int_distribution(l, r)(rng); } template B conv(const A &a, B b = B()) { stringstream s; s << a, s >> b; return b; } template T inf() { return numeric_limits::max() / 2; } template T sign(const T &a) { return a == 0 ? 0 : (a < 0 ? -1 : 1); } template T floor(const T &a, const T &b) { assert(b != 0); return sign(a) * sign(b) > 0 ? abs(a) / abs(b) : -(abs(a) + abs(b) - 1) / abs(b); } template T ceil(const T &a, const T &b) { assert(b != 0); return sign(a) * sign(b) > 0 ? (abs(a) + abs(b) - 1) / abs(b) : -abs(a) / abs(b); } template bool tmin(T &a, T b) { return b < a ? a = b, true : false; } template bool tmax(T &a, T b) { return b > a ? a = b, true : false; } #if __cplusplus > 201103L template auto min(const T &a) { return *min_element(rang(a)); } template auto max(const T &a) { return *max_element(rang(a)); } template auto sum(const T &a) { return accumulate(rang(a), (typename T::value_type)0); } template <> auto sum(const vector &a) { return accumulate(rang(a), 0ll); } template <> auto sum(const vector &a) { return accumulate(rang(a), string()); } template auto find(C &c, const V &v) { return find(rang(c), v); } template auto find(const C &c, const V &v) { return find(rang(c), v); } #endif template > void sort(T &a, C c = C()) { sort(rang(a), c); } template void reve(T &a) { reverse(rang(a)); } template void uniq(T &a) { sort(a), a.erase(unique(rang(a)), end(a)); } template void shuf(T &a) { shuffle(rang(a), rng); } template void merg(T l, T m, T r) { inplace_merge(l, m, r); } #if __cplusplus > 201103L template auto vect(const T &v, int n) { return vector(n, v); } template auto vect(const T &v, int n, D... m) { return vector(n, vect(v, m...)); } #endif template istream &operator>>(istream &s, pair &a) { return s >> a.first >> a.second; } template ostream &operator<<(ostream &s, const pair &a) { return s << a.first << " " << a.second; } template istream &operator>>(istream &s, vector &a) { for (int i = -1; i < 0 && (!a.size() && (cin >> i, a.resize(i), 0), i = 0), i < int(a.size());) s >> a[i++]; return s; } template ostream &operator<<(ostream &s, const vector &a) { lv(i, a) cout << a[i] << (i + 1 == int(a.size()) ? "" : " "); return s; } template T in() { T a; cin >> a; return a; } template istream &in(T &a) { return cin >> a; } template istream &in(A &a, B &... b) { return cin >> a, in(b...); } void ou() { cout << endl; } template void ou(const T &a) { cout << a << endl; } template void ou(const A &a, const B &... b) { cout << a << ' ', ou(b...); } bool yep(const bool &a) { return ou(a ? "yes" : "no"), a; } bool Yep(const bool &a) { return ou(a ? "Yes" : "No"), a; } bool YEP(const bool &a) { return ou(a ? "YES" : "NO"), a; } #if __cplusplus > 201103L template struct func { func(T &&t_) : t(forward(t_)) {} template auto operator()(A &&... a) const { return t(*this, forward(a)...); } T t; }; #endif template struct hash_safe {}; template <> struct hash_safe { size_t operator()(unsigned long long a) const { static unsigned long long d = chrono::steady_clock::now().time_since_epoch().count(); a += d + 0x9e3779b97f4a7c15, a = (a ^ (a >> 30)) * 0xbf58476d1ce4e5b9; a = (a ^ (a >> 27)) * 0x94d049bb133111eb; return a ^ (a >> 31); } }; template <> struct hash_safe { size_t operator()(unsigned long long a) const { return hash_safe()(a); } }; template struct hash_safe> { size_t operator()(pair a) const { auto h = hash_safe()(a.first), g = hash_safe()(a.second); return (h >> 16 << 16) + (g >> 16); } }; template using unordered_set_safe = unordered_set>; template using unordered_multiset_safe = unordered_multiset>; template using unordered_map_safe = unordered_map>; template using unordered_multimap_safe = unordered_multimap>; #define unordered_set unordered_set_safe #define unordered_multiset unordered_multiset_safe #define unordered_map unordered_map_safe #define unordered_multimap unordered_multimap_safe template > using bbst = tree; template > using heap = __gnu_pbds::priority_queue; using ll = long long; using ld = long double; using str = string; using pii = pair; using pll = pair; using vi = vector; using vl = vector; using vpii = vector; using vpll = vector; using vvi = vector; // The templates end here. int main() { ios::sync_with_stdio(0); cout << setprecision(16) << fixed; cin.tie(0); many { int n; in(n); map ev; lp(i, 0, n - 1) { int t; in(t); while (t--) { int tm, p; in(tm, p); ev[pii(tm, p)].push_back(i); } } vi ans(n); ans[0] = 1; for (auto tt : ev) { int aa = 0; for (auto i : tt.second) if (ans[i]) aa = 1; if (aa == 0) continue; for (auto i : tt.second) ans[i] = 1; } vi ans2; lp(i, 0, n - 1) if (ans[i]) ans2.push_back(i + 1); ou(ans2); } return 0; }