#include #define Max(a,b) ((ab)&&(a=b)) #define rep(i,a,b) for(int i=a,i##end=b;i<=i##end;++i) #define drep(i,a,b) for(int i=a,i##end=b;i>=i##end;--i) #define erep(i,a) for(int i=hd[a],y;(y=to[i]);i=nxt[i]) using namespace std; typedef long long ll; char C; inline int rd() { int res=0,f=1; while(C=getchar(),C<48||C>57)if(C=='-')f=0; do res=(res<<3)+(res<<1)+(C^48); while(C=getchar(),C>=48&&C<=57); if(f)return res; return -res; } const int M=20005; bool mk[M]; vectorv[105][15]; int main(){ int T=rd(); while(T--){ int n=rd(); rep(i,1,100)rep(j,1,10)v[i][j].clear(); memset(mk,0,sizeof mk); mk[1]=1; rep(i,1,n){ int c=rd(); while(c--){ int t=rd(),p=rd(); v[t][p].push_back(i); } } rep(i,1,100)rep(j,1,10){ bool ok=0; rep(k,0,(int)v[i][j].size()-1)ok|=mk[v[i][j][k]]; if(ok)rep(k,0,(int)v[i][j].size()-1)mk[v[i][j][k]]=1; } cout<<1; rep(i,2,n)if(mk[i])cout<<" "<