#include using namespace std; int t, n, m, p; int is[20010]; vector a[110][110]; int main() { scanf("%d", &t); while (t--) { for (int i = 1; i <= 100; ++i) for (int j = 1; j <= 10; ++j) a[i][j].clear(); memset(is, 0, sizeof is); scanf("%d", &n); for (int i = 1; i <= n; ++i) { int k; scanf("%d", &k); while (k--) { int t, p; scanf("%d%d", &t, &p); a[t][p].push_back(i); } } is[1] = 1; for (int i = 1; i <= 100; ++i) for (int j = 1; j <= 10; ++j) { int s = 0; for (int k = 0; k < (int)a[i][j].size(); ++k) s += is[a[i][j][k]]; if (s) { for (int k = 0; k < (int)a[i][j].size(); ++k) is[a[i][j][k]] = 1; } } vector all; for (int i = 1; i <= n; ++i) if (is[i]) all.push_back(i); for (int i = 0; i < (int)all.size(); ++i) printf("%d%c", all[i], " \n"[i == (int)all.size() - 1]); } }