n = int(input()) a = [] p = [] for i in range(n): a.append(list(map(int,input().split()))) p.append(a[i][0]) ans = [] for i in range(max(p)): for j in range(n): if len(a[j]) != 1: ans.append(a[j][1]) a[j].pop(1) print(' '.join(map(str, ans)))