#include #include #include using namespace std; vector mp[105][15]; int tag[200000]; int n,T; bool check(vector& v){ for(int i = 0; i < v.size(); ++i){ if(tag[v[i]] == 1) return true; } return false; } void spr(vector& v){ for(int i = 0; i < v.size(); ++i){ tag[v[i]] = 1; } } int main(){ tag[1] = 1; scanf("%d", &T); while (T --){ scanf("%d", &n); for(int i = 2; i <= n; ++i) tag[i] = 0; for(int t = 1; t <= 100; ++t){ for(int p = 1; p <= 10; ++p){ mp[t][p].clear(); } } for(int i = 1; i <= n; ++i){ int len; scanf("%d", &len); for(int o = 1; o <= len; ++o){ int t, p; scanf("%d%d", &t, &p); mp[t][p].push_back(i); } } for(int t = 1; t <= 100; ++t){ for(int p = 1; p <= 10; ++p){ if(mp[t][p].empty()) continue; if(check(mp[t][p])){ spr(mp[t][p]); } } } vector ans; ans.clear(); for(int i = 1; i <= n; ++i){ if(tag[i]){ ans.push_back(i); } } printf("%d", ans[0]); for(int i = 1; i < ans.size(); ++i){ printf(" %d", ans[i]); } printf("\n"); } return 0; }