#include using namespace std; typedef long long ll; typedef unsigned long long ull; #define Rep(i,a,b) for(register int i=(a);i<=(b);++i) #define rep(i,a,b) for(register int i=(a);i<(b);++i) #define Dep(i,a,b) for(register int i=(a);i>=(b);--i) #define mem(x,v) memset(x,v,sizeof(x)) #define gc getchar #define pc putchar inline ll read(){ ll x = 0,f = 0;char c = gc(); for(;!isdigit(c);c=gc()) f|=(c=='-'); for(;isdigit(c);c=gc()) x = x * 10 + (c - '0'); return f ? -x : x; } inline void write(ll x){if(x < 0) pc('-'),x=-x;if(x>=10) write(x / 10);pc(x%10+'0');} inline void writeln(ll x){write(x),pc('\n');} inline void wri(ll x){write(x),pc(' ');} const int N=20005; int n; int vis[N]; vector vec[105][14]; void solve(){ memset(vis,false,sizeof(vis)); n=read(); int t=100,p=10; Rep(i,1,t)Rep(j,1,p)vec[i][j].clear(); Rep(i,1,n){ int len=read(); while (len--){ int t=read(),p=read(); vec[t][p].push_back(i); } } vis[1]=1; Rep(i,1,t)Rep(j,1,p){ int f=0; for(auto k:vec[i][j]) f|=vis[k]; if(f) for(auto k:vec[i][j]) vis[k]|=f; } int flag=0; Rep(i,1,n) if(vis[i]){ if(flag) pc(' '); flag=true; write(i); } puts(""); } int main(){ int T=read(); while (T--) solve(); return 0; }