# Arup Guha
# 12/11/2024
# Solution to UCF HS Online Div 2 Problem: Clout Chasing

# Returns 1 for an alliterative name, 0 for a non alliterative name.
def ascore(name):

    # Check for alliteration.
    if name[0][0] == name[1][0]:
        return 1

    # None to be found.
    return 0

# Returns the sum of the lengths of the strings in name.
def sumlen(name):

    res = 0
    for x in name:
        res += len(x)
    return res

# Returns true if name beats oldname
def beat(name, oldname):

    # One way we could win
    if ascore(name) > ascore(oldname):
        return True

    # Here we don't.
    if ascore(name) < ascore(oldname):
        return False

    # We break ties by total name length.
    if sumlen(name) > sumlen(oldname):
        return True

    # We didn't beat oldname if we get here.
    return False
    
# Get input.
n = int(input())

# Assume this is the best.
res = input().split()

# Go through the rest.
for i in range(1,n):

    # Read this name.
    tmp = input().split()

    # Update res if this one's better.
    if beat(tmp, res):
        res = tmp
        
# Print it!
print(res[0],res[1])
