# Arup Guha
# 7/12/2025
# Solution to 2025 SI@UCF CP Camp Contest #1 Problem: Galactic Studio

nC = int(input())

# Process cases.
for loop in range(nC):

    # Get number of entries.
    n = int(input())

    # Set up dictionary.
    mymap = {}

    # Process additions
    for i in range(n):

        # Get addition.
        toks = input().split()
        name = toks[0]
        count = int(toks[1])

        # Already there, add it.
        if name in mymap:
            mymap[name] += count

        # Make new entry.
        else:
            mymap[name] = count

    # These will be overwritten.
    res = 0
    ans = ""

    # Go through all entries, looking for the largest.
    for park in mymap:
        if mymap[park] > res:
            res = mymap[park]
            ans = park

    # Ta da!
    print(ans)
