a = []
x = 0
for i in range(2):
a.append(input())
if x == 0:
x = int(input())
else:
if x > int(input()):
print(a[1])
print(a[0])
arr = [{'name': input(), 'age': int(input())} for i in range(2)]
arr = sorted(arr, key=lambda x: x['age'])
print(arr[0]['name'])
a = []
x = 0
for i in range(2):
a.append(input())
if x == 0:
x = int(input())
else:
if x > int(input()):
print(a[1])
else:
print(a[0])
arr = [{'name': input(), 'age': int(input())} for i in range(2)]
arr = sorted(arr, key=lambda x: x['age'])
print(arr[0]['name'])