l=[] cnt=0 n=int(input()) for i in range(n): q=list(map(int,input().split())) if q[0]==0: continue l.append(q[1:]) cnt=0 ans=[] while l: for x in l: if len(x)==0: continue ans.append(x.pop(0)) print(ans)