N = int(input()) queue = [] for i in range(N): k, *a = map(int, input().split()) queue.append(a) ans = [] while sum([len(q) for q in queue]) > 0: for i in range(N): if len(queue[i]) > 0: ans.append(queue[i].pop(0)) print(*ans)