#include using namespace std; typedef long long ll; typedef pair PII; const int MAXN = 1e5 + 10; const int MM = 1e9 + 7; int n, m; vector E[114][20]; int vis[MAXN]; void solve(int casi){ scanf("%d", &n); for (int i = 1; i <= n; i++) vis[i] = 0; vis[1] = 1; for (int i = 0; i <= 110; i++) { for (int j = 1; j <= 10; j++) E[i][j].clear(); } for (int i = 1; i <= n; i++) { scanf("%d", &m); int t, p; for (int j = 1; j <= m; j++) { scanf("%d%d", &t, &p); E[t][p].emplace_back(i); } } for (int t = 1; t <= 100; t++) { for (int p = 1; p <= 10; p++) { int flag = 0; for (auto &x : E[t][p]) if (vis[x]) flag = 1; if (flag) { for (auto &x : E[t][p]) vis[x] = 1; } } } vector ans; for (int i = 1; i <= n; i++) if (vis[i]) ans.push_back(i); for (int i = 0; i < ans.size(); i++) { printf("%d%c", ans[i], " \n"[i + 1 == ans.size()]); } } int main(){ int T = 1; scanf("%d", &T); for (int i = 1; i <= T; i++) solve(i); return 0; }