n=int(input()) line=[] for i in range(n): p=list(map(int,input().split())) if p[0]==0: continue a=p[1:][::-1] line.append(a) ans=[] while line: ne=[] for x in line: tmp=x.pop() ans.append(tmp) if len(x)!=0: ne.append(x) line=ne print(*ans)