# include using namespace std; namespace Base{ # define mr make_pair typedef long long ll; typedef double db; const int inf = 0x3f3f3f3f, INF = 0x7fffffff; const ll infll = 0x3f3f3f3f3f3f3f3fll, INFll = 0x7fffffffffffffffll; template void read(T &x){ x = 0; int fh = 1; double num = 1.0; char ch = getchar(); while (!isdigit(ch)){ if (ch == '-') fh = -1; ch = getchar(); } while (isdigit(ch)){ x = x * 10 + ch - '0'; ch = getchar(); } if (ch == '.'){ ch = getchar(); while (isdigit(ch)){num /= 10; x = x + num * (ch - '0'); ch = getchar();} } x = x * fh; } template void chmax(T &x, T y){x = x < y ? y : x;} template void chmin(T &x, T y){x = x > y ? y : x;} } using namespace Base; const int M = 1010, N = 100100; int use[N], n; vector mp[M]; int main(){ int T; read(T); while (T--){ read(n); for (int i = 0; i < 1000; i++) mp[i].clear(); for (int i = 1; i <= n; i++){ int num; read(num); for (int j = 1; j <= num; j++){ int t, p; read(t); read(p); int id = (t - 1) * 10 + (p - 1); mp[id].push_back(i); } } memset(use, inf, sizeof(use)); use[1] = 0; for (int i = 0; i < 1000; i++){ bool flag = false; for (unsigned j = 0; j < mp[i].size(); j++) if (use[mp[i][j]] <= i / 10) flag = true; if (!flag) continue; for (unsigned j = 0; j < mp[i].size(); j++) use[mp[i][j]] = min(use[mp[i][j]], i / 10 + 1); } printf("%d", 1); for (int i = 2; i <= n; i++) if (use[i] != inf){ printf(" %d", i); } printf("\n"); } return 0; }