n, l = map(int, input().split())

s = sorted([input() for _ in range(n)])

print(*s, sep='')

n, l = map(int, input().split())

print(*sorted([input() for _ in range(n)]), sep='')

n, l = map(int, input().split())
s = sorted([input() for _ in range(n)])
print(*s, sep="")

n, l = map(int, input().split())
print(*sorted([input() for _ in range(n)]), sep="")

-s = sorted([input() for _ in range(n)]) -print(*s, sep="") +print(*sorted([input() for _ in range(n)]), sep="")