N = int(input()) As = [] for _ in range(N): PA = list(map(int, input().split())) P = PA.pop(0) if PA: As.append(PA) result = [] while As: A = As.pop(0) a = A.pop(0) result.append(a) if A: As.append(A) print(' '.join(str(a) for a in result))