

import sys
input = sys.stdin.readline # 줄바꿈문자도 같이 가져옴
n = int(input())
words = []
for i in range(n):
line = input().rstrip() # 오른쪽 공백문자 제거
words.append(line)
max_len = -1
ans_list = []
for i in range(n):
for k in range(n):
if i == k:
continue
len_1 = len(words[i])
len_2 = len(words[k])
word_len = min(len_1, len_2)
same_len = 0
for j in range(word_len):
if words[i][j] != words[k][j]:
same_len = j
break
else:
same_len = word_len
# words[i][0]와 words[i+1][0]의 동일 접두사 길이로 최댓값 갱신
if same_len > max_len:
ans_list.clear()
max_len = same_len
idx_1 = i
idx_2 = k
if idx_1 > idx_2:
temp = idx_2
idx_2 = idx_1
idx_1 = temp
ans_list.append([idx_1, idx_2])
elif same_len == max_len:
idx_1 = i
idx_2 = k
if idx_1 > idx_2:
temp = idx_2
idx_2 = idx_1
idx_1 = temp
# 기존 인덱스보다 더 앞의 인덱스인 경우에만 갱신
if [idx_1, idx_2] < ans_list[0]:
ans_list[0] = [idx_1, idx_2]
str_1 = words[ans_list[0][0]]
str_2 = words[ans_list[0][1]]
print(str_1)
print(str_2)