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