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



list = []



for i in range(n):

    list.append("{}".format(input()))



list.sort()



for i2 in range(n):

    print(list[i2],end="")

n = input().split()



word_list = []



for i in range(int(n[0])):

    word_list.append(eval(input()))



sorted_list = sorted(word_list)

answer = "".join(sorted_list)

print(answer)
n, l = map(int, input().split())
list = []
for i in range(n):
    list.append("{}".format(input()))
list.sort()
for i2 in range(n):
    print(list[i2], end="")

n = input().split()
word_list = []
for i in range(int(n[0])):
    word_list.append(eval(input()))
sorted_list = sorted(word_list)
answer = "".join(sorted_list)
print(answer)

-n, l = map(int, input().split()) -list = [] -for i in range(n): -    list.append("{}".format(input())) -list.sort() -for i2 in range(n): -    print(list[i2], end="") +n = input().split() +word_list = [] +for i in range(int(n[0])): +    word_list.append(eval(input())) +sorted_list = sorted(word_list) +answer = "".join(sorted_list) +print(answer)