#include #include #include #include #include #include #include using namespace std; const int N = 2e4 + 10, T = 110, P = 15; int t; int n; map > book; bool st[N]; // 感染情况 int maxt, maxp; int cnt; int main() { cin >> t; while (t--) { book.clear(); st[1] = true; maxt = -1, maxp = -1; scanf("%d", &n); int l, t, p; for (int i = 1; i <= n; i++) { if (i != 1) st[i] = false; scanf("%d", &l); while (l--) { scanf("%d%d", &t, &p); string time_pos = to_string(t) + "#" + to_string(p); maxt = max(maxt, t); maxp = max(maxp, p); // g[t][p][++g[t][p][0]] = i; if (book.find(time_pos) == book.end()) { // 没有该时刻-位置信息 pair > temp; temp.first = time_pos; book.insert(temp); book.find(time_pos)->second.push_back(i); } else { book.find(time_pos)->second.push_back(i); } } } bool flag; for (int i = 1; i <= maxt; i++) { for (int j = 1; j <= maxp; j++) { // 对于i时刻, j位置来说 string time_pos = to_string(i) + "#" + to_string(j); std::map >::iterator it = book.find(time_pos); if (it == book.end()) { continue; } flag = false; int cnt = it->second.size(); for (int k = 0; k < cnt; k++) { if (st[it->second[k]]) { flag = true; break; } } if (flag) { for (int k = 0; k < cnt; k++) { st[it->second[k]] = true; } } } } cnt = 0; for (int i = 1; i <= n; i++) { if (st[i] == true) { cnt++; } } for (int i = 1; i <= n; i++) { if (st[i] == true) { if (cnt == 1) { printf("%d", i); } else { printf("%d ", i); cnt--; } } } cout << endl; } return 0; }