from collections import deque n = int(input()) q = deque() for _ in range(n): p, *a = map(int,input().split()) q.append(a[::-1]) ans = [] while q: v = q.popleft() if v: ans.append(v.pop()) if v: q.append(v) print(*ans)