a,*b=open(0) p={} def f(x): if x!=p.get(x,x):p[x]=x=f(p[x]) return x for s in b: q,a,b=map(f,s.split()) if'0'