n = int(input())
list_input = [input() for i in range (n)]#接收n个输入
list_dic = ' '.join(sorted(list_input)).split(' ')#空格加入列表,空格分割元素
for i in list_dic:#依次print
print(i)
n = int(input())
list_input = [input() for i in range (n)]#接收n个输入
list_dic = ' '.join(sorted(list_input)).split(' ')#空格加入列表,空格分割元素
for i in list_dic:#依次print
print(i)