#include #include #include #include #define RI register int #define int long long using namespace std; vector V[105][15]; int vis[20005]; int ans[20005]; signed main() { //freopen("a.in", "r", stdin); int T; scanf("%lld", &T); while (T--) { memset(vis, 0, sizeof(vis)); vis[1] = 1; int n; scanf("%lld", &n); for (RI i = 1; i <= 100; ++i) for (RI j = 1; j <= 10; ++j) V[i][j].clear(); for (RI i = 1; i <= n; ++i) { int len; scanf("%lld", &len); for (RI j = 1; j <= len; ++j) { int t, p; scanf("%lld %lld", &t, &p); V[t][p].push_back(i); } } for (RI i = 1; i <= 100; ++i) for (RI j = 1; j <= 10; ++j) { int si = V[i][j].size(); int flag = 0; for (RI k = 0; k < si; ++k) flag |= vis[V[i][j][k]]; for (RI k = 0; k < si; ++k) vis[V[i][j][k]] |= flag; } int cnt = 0; for (RI i = 1; i <= n; ++i) if (vis[i]) ans[++cnt] = i; for (RI i = 1; i <= cnt; ++i) printf("%lld%c", ans[i], " \n"[i == cnt]); } return 0; }