#include //#include //#include //#include //#include //#include //#include //#include //#include //#include //#include //#include #define X first #define Y second #define PB push_back #define MP make_pair #define EB emplace_back #define mset(var,val) memset(var,val,sizeof(var)) #define IOS ios::sync_with_stdio(false);cin.tie(0),cout.tie(0) #define rep(i,n) for(int i = 0; i < n; ++i) #define rep1(i,n) for(int i = 1; i <= n; ++i) //using namespace __gnu_pbds; //using namespace __gnu_cxx; using namespace std; namespace ___ { #ifdef local #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0) void err() { cout << endl; } template class T, typename t, typename... Args> void err(T a, Args... args) { for (auto x: a) cout << x << ' '; err(args...); } template void err(T a, Args... args) { cout << a << ' '; err(args...); } #else #define dbg(...) #endif //#ifdef local //typedef long long LL; //#else //typedef __int128 LL; //#endif // local int _ = 0; void testcase() { cout << "Case " << (++_) << ": "; } } template inline bool scan(T&ret) { char c; int sgn; if(c=getchar(),c==EOF) return 0; while(c!='-' and (c<'0' or c>'9')) c=getchar(); sgn=(c=='-')?-1:1; ret=(c=='-')?0:(c-'0'); while(c=getchar(),c>='0' and c<='9') ret=ret*10+(c-'0'); ret*=sgn; return 1; } template inline void out(T x) { if(x>9) out(x/10); putchar(x%10+'0'); } using namespace ___; typedef long long ll; typedef unsigned long long ull; typedef unsigned int uint; typedef pair pii; typedef pair pll; const int inf = 0x3f3f3f3f; const ll INF = 0x3f3f3f3f3f3f3f3fLL; const double PI = acos(-1.0); const double eps = 1e-6; const int mod = 998244353; const int lim = 1e3; const int N = 2e6+10; const int M = 1e6+10; #define lson (rt<<1) #define rson (rt<<1|1) ll qpow(ll a, ll b) { ll ans = 1; for(;b;b>>=1){ if(b&1) ans = ans*a%mod; a=a*a%mod; } return ans; } bool vis[N]; vector a[N]; int early[N]; vector b[105][12]; bool visp[105][12]; priority_queue, greater >q; void work(){ int n; cin >> n; while(!q.empty()) q.pop(); rep1(i,100){ rep1(j,10) { b[i][j].clear(); visp[i][j] = 0; } } rep1(i,n) { a[i].clear(); early[i] = inf; vis[i] = 0; int len; cin >> len; rep(j,len) { int x, y; cin >> x >> y; a[i].emplace_back(x, y); b[x][y].push_back(i); } } q.emplace(0,1); early[1] = 0; while(!q.empty()) { pii tp = q.top(); int u = tp.Y; q.pop(); if(vis[u] or tp.X != early[u]) continue; vis[u] = true; // dbg(u); for (auto &p : a[u]) { auto &x = p.X; auto &y = p.Y; if (x < early[u]) continue; if (visp[x][y]) continue; visp[x][y] = 1; for (auto &v : b[x][y]) { if (x > early[v]) continue; early[v] = x; q.emplace(x,v); } } } rep1(i,n){ if (early[i] < inf) { if (i != 1) cout << " "; cout << i; } } cout << "\n"; } int main() { #ifdef local freopen("in.txt","r",stdin); // freopen("out.txt","w",stdout); #endif // local IOS; // init(); int t; cin>>t; // for(; t--;) work(); // return 0; }