w = list(map(int,input().split()))
n = [w[1]]
s = w[-1]
x = w[2:-1]
dian_xu = []
dian_zi = []
for i in range(len(x)):
if i%2 == 0:
dian_xu.append(x[i])
elif i%2 != 0:
dian_zi.append(x[i])
for i in range(len(dian_xu)):
nx = n.index(dian_zi[i])
n.insert(nx + 1, dian_xu[i])
n.remove(s)
if len(n) == 0:
print(None)
else:
n = map(str, n)
print(' '.join(n))
n = [w[1]]
s = w[-1]
x = w[2:-1]
dian_xu = []
dian_zi = []
for i in range(len(x)):
if i%2 == 0:
dian_xu.append(x[i])
elif i%2 != 0:
dian_zi.append(x[i])
for i in range(len(dian_xu)):
nx = n.index(dian_zi[i])
n.insert(nx + 1, dian_xu[i])
n.remove(s)
if len(n) == 0:
print(None)
else:
n = map(str, n)
print(' '.join(n))