L = list(map(int,input().split()))
N = L[0]
L = L[2:]
new_L = []
new_L.append(L[1])
while len(L) > 1:
a,b = L[0:2]
new_L.insert(new_L.index(b)+1,a)
L = L[2:]
else:
new_L.remove(L[-1])
print(*new_L)
L = list(map(int,input().split()))
N = L[0]
L = L[2:]
new_L = []
new_L.append(L[1])
while len(L) > 1:
a,b = L[0:2]
new_L.insert(new_L.index(b)+1,a)
L = L[2:]
else:
new_L.remove(L[-1])
print(*new_L)