N = int(input())

restaurants = {}
for i in range(1, N+1):
    s, p = input().split()
    restaurants[i] = (s, int(p))

key = lambda x: x[1]
restaurants_sorted = sorted(restaurants.items(), key=key)

city_restraurant = []
city = ""
for restaurant in restaurants_sorted:
    if not city:
        city = restaurant[1][0]
        city_restraurant.append((restaurant[0], restaurant[1][1]))
    elif city == restaurant[1][0]:
        city_restraurant.append((restaurant[0], restaurant[1][1]))
    else:
        city_restraurant.sort(key=lambda x: x[1], reverse=True)
        for c in city_restraurant:
            print(c[0])
        city_restraurant = [(restaurant[0], restaurant[1][1])]
        city = restaurant[1][0]
city_restraurant.sort(key=lambda x: x[1], reverse=True)
for c in city_restraurant:
    print(c[0]) N = int(input()) N int(input()) int input() input restaurants = {} restaurants {} for i in range(1, N+1):
    s, p = input().split()
    restaurants[i] = (s, int(p)) i range(1, N+1) range 1 N+1 N 1 s, p = input().split() s input().split() ().split () input split p restaurants[i] = (s, int(p)) restaurants[i] restaurants i (s, int(p)) s int(p) int p key = lambda x: x[1] key lambda x: x[1] x[1] x 1 x restaurants_sorted = sorted(restaurants.items(), key=key) restaurants_sorted sorted(restaurants.items(), key=key) sorted restaurants.items() restaurants.items restaurants items key=key key key city_restraurant = [] city_restraurant [] city = "" city "" for restaurant in restaurants_sorted:
    if not city:
        city = restaurant[1][0]
        city_restraurant.append((restaurant[0], restaurant[1][1]))
    elif city == restaurant[1][0]:
        city_restraurant.append((restaurant[0], restaurant[1][1]))
    else:
        city_restraurant.sort(key=lambda x: x[1], reverse=True)
        for c in city_restraurant:
            print(c[0])
        city_restraurant = [(restaurant[0], restaurant[1][1])]
        city = restaurant[1][0] restaurant restaurants_sorted if not city:
        city = restaurant[1][0]
        city_restraurant.append((restaurant[0], restaurant[1][1]))
    elif city == restaurant[1][0]:
        city_restraurant.append((restaurant[0], restaurant[1][1]))
    else:
        city_restraurant.sort(key=lambda x: x[1], reverse=True)
        for c in city_restraurant:
            print(c[0])
        city_restraurant = [(restaurant[0], restaurant[1][1])]
        city = restaurant[1][0] not city city city = restaurant[1][0] city restaurant[1][0] [1] restaurant 1 0 city_restraurant.append((restaurant[0], restaurant[1][1])) city_restraurant.append city_restraurant append (restaurant[0], restaurant[1][1]) restaurant[0] restaurant 0 restaurant[1][1] [1] restaurant 1 1 elif city == restaurant[1][0]:
        city_restraurant.append((restaurant[0], restaurant[1][1]))
     city == restaurant[1][0] city restaurant[1][0] [1] restaurant 1 0 city_restraurant.append((restaurant[0], restaurant[1][1])) city_restraurant.append city_restraurant append (restaurant[0], restaurant[1][1]) restaurant[0] restaurant 0 restaurant[1][1] [1] restaurant 1 1 city_restraurant.sort(key=lambda x: x[1], reverse=True) city_restraurant.sort city_restraurant sort key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True for c in city_restraurant:
            print(c[0])
         c city_restraurant print(c[0]) print c[0] c 0 city_restraurant = [(restaurant[0], restaurant[1][1])] city_restraurant [(restaurant[0], restaurant[1][1])] (restaurant[0], restaurant[1][1]) restaurant[0] restaurant 0 restaurant[1][1] [1] restaurant 1 1 city = restaurant[1][0] city restaurant[1][0] [1] restaurant 1 0 city_restraurant.sort(key=lambda x: x[1], reverse=True) city_restraurant.sort city_restraurant sort key=lambda x: x[1] key lambda x: x[1] x[1] x 1 x reverse=True reverse True for c in city_restraurant:
    print(c[0]) c city_restraurant print(c[0]) print c[0] c 0 city = restaurant[1][0] restaurant[1][0] city key = lambda x: x[1] lambda x: x[1] key restaurants = {} {} restaurants city = restaurant[1][0] restaurant[1][0] city city_restraurant = [(restaurant[0], restaurant[1][1])] [(restaurant[0], restaurant[1][1])] city_restraurant restaurants_sorted = sorted(restaurants.items(), key=key) sorted(restaurants.items(), key=key) restaurants_sorted p = input().split() input().split() p s, p = input().split() input().split() s city_restraurant = [] [] city_restraurant city = "" "" city N = int(input()) int(input()) N
N = int(input())

restaurants = {}
for i in range(1, N+1):
    s, p = input().split()
    restaurants[i] = (s, int(p))

key = lambda x: x[1]
restaurants_sorted = sorted(restaurants.items(), key=key)

city_restraurant = []
city = ""
for restaurant in restaurants_sorted:
    if not city:
        city = restaurant[1][0]
        city_restraurant.append((restaurant[0], restaurant[1][1]))
    elif city == restaurant[1][0]:
        city_restraurant.append((restaurant[0], restaurant[1][1]))
    else:
        city_restraurant.sort(key=lambda x: x[1], reverse=True)
        for c in city_restraurant:
            print(c[0])
        city_restraurant = [(restaurant[0], restaurant[1][1])]
        city = restaurant[1][0]
city_restraurant.sort(key=lambda x: x[1], reverse=True)
for c in city_restraurant:
    print(c[0])