https://www.acmicpc.net/problem/1302
selling_count = int(input())
data = {}
for _ in range(selling_count):
book = input().strip()
if book in data.keys():
data[book] += 1
else:
data[book] = 1
max_count = max(data.values())
result = list(filter(lambda x: data[x]==max_count, data.keys()))
print(sorted(result)[0])
n = int(input())
books = {}
for _ in range(n):
book = input()
if book not in books:
books[book] = 1
else:
books[book] += 1
target = max(books.values())
array = []
for book, number in books.items():
if number == target:
array.append(book)
print(sorted(array)[0])