l = []
while True:
try:
lines = int(input())
for i in range(lines):
da = input()
l.append(da)
except:
break
for j in sorted(l):
print(j)
l = []
while True:
try:
lines = int(input())
for i in range(lines):
da = input()
l.append(da)
except:
break
for j in sorted(l):
print(j)