import collections N = int(input()) ls = [] for i in range(N): a = list(map(int,input().split())) if len(a) == 1: ls.append(collections.deque()) else: ls.append(collections.deque(a[1:])) ans = [] while ls: ll = [] for q in ls: if not q: continue ans.append(q.popleft()) ll.append(q) ls = ll print(*ans)