/* * @Author: hesorchen * @Date: 2020-07-03 17:05:01 * @LastEditTime: 2020-07-25 15:24:42 * @Description: https://hesorchen.github.io/ */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; #define endl '\n' #define PI acos(-1) #define PB push_back #define ll long long #define INF 0x3f3f3f3f #define mod 1000000007 #define pll pair #define lowbit(abcd) (abcd & (-abcd)) #define max(a, b) ((a > b) ? (a) : (b)) #define min(a, b) ((a < b) ? (a) : (b)) #define IOS \ ios::sync_with_stdio(false); \ cin.tie(0); \ cout.tie(0); #define FRE \ { \ freopen("in.txt", "r", stdin); \ freopen("out.txt", "w", stdout); \ } inline ll read() { ll x = 0, f = 1; char ch = getchar(); while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); } while (ch >= '0' && ch <= '9') { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); } return x * f; } //head============================================================================== int mp[110][11]; int ans[20010], ct = 1; int tong[20010]; vector vec[20010]; int main() { IOS; ll t; cin >> t; while (t--) { fill(mp[0], mp[0] + 110 * 11, 0); fill(tong, tong + 20010, 0); // vec->clear(); for (int i = 1; i <= 20000; i++) vec[i].clear(); ct = 1; ll n, maxt = 0; cin >> n; for (int i = 1; i <= n; i++) { ll m, t, p; cin >> m; for (int j = 1; j <= m; j++) cin >> t >> p, vec[i].push_back(make_pair(t, p)), maxt = max(maxt, t); } for (auto pt = vec[1].begin(); pt != vec[1].end(); pt++) { int tt = pt->first, pp = pt->second; mp[tt][pp] = 1; } for (int i = 1; i <= maxt; i++) { for (int k = 1; k <= n; k++) { int flag = 0; for (auto j = vec[k].begin(); j != vec[k].end(); j++) { int tt = j->first, pp = j->second; if (tt < i) continue; if (tong[k]) { mp[tt][pp] = 1; continue; } if (tt == i && mp[tt][pp]) { flag = 1; //k被染色 ans[ct++] = k; // cout << k << endl; tong[k] = 1; } // if (tt >= i) // break; } } } sort(ans + 1, ans + ct); int newend = unique(ans + 1, ans + ct) - ans; cout << ans[1]; for (int i = 2; i < newend; i++) cout << ' ' << ans[i]; cout << endl; } return 0; } /* 1 3 1 1 1 1 3 3 2 1 1 3 3 */