N = int(input())
city={}
city_name=[]
for n in range(N):
    S = input().split()
    city[n+1]=S
    city_name.append(S[0])

city_name=list(set(city_name))
city_name.sort()

for c_name in city_name:
    city_temp = {}
    for c_key in city.keys():
        if city[c_key][0] == c_name:
            city_temp[int(city[c_key][1])]=c_key
            
    p_temp = list(city_temp.keys())
    p_temp.sort(reverse=True)
    for v in p_temp:
        print(city_temp[v]) N = int(input()) N int(input()) int input() input city={} city {} city_name=[] city_name [] for n in range(N):
    S = input().split()
    city[n+1]=S
    city_name.append(S[0]) n range(N) range N S = input().split() S input().split() ().split () input split city[n+1]=S city[n+1] city n+1 n 1 S city_name.append(S[0]) city_name.append city_name append S[0] S 0 city_name=list(set(city_name)) city_name list(set(city_name)) list set(city_name) set city_name city_name.sort() city_name.sort city_name sort for c_name in city_name:
    city_temp = {}
    for c_key in city.keys():
        if city[c_key][0] == c_name:
            city_temp[int(city[c_key][1])]=c_key
            
    p_temp = list(city_temp.keys())
    p_temp.sort(reverse=True)
    for v in p_temp:
        print(city_temp[v]) c_name city_name city_temp = {} city_temp {} for c_key in city.keys():
        if city[c_key][0] == c_name:
            city_temp[int(city[c_key][1])]=c_key
            
     c_key city.keys() city.keys city keys if city[c_key][0] == c_name:
            city_temp[int(city[c_key][1])]=c_key
            
     city[c_key][0] == c_name city[c_key][0] [c_key] city c_key 0 c_name city_temp[int(city[c_key][1])]=c_key city_temp[int(city[c_key][1])] city_temp int(city[c_key][1]) int city[c_key][1] [c_key] city c_key 1 c_key p_temp = list(city_temp.keys()) p_temp list(city_temp.keys()) list city_temp.keys() city_temp.keys city_temp keys p_temp.sort(reverse=True) p_temp.sort p_temp sort reverse=True reverse True for v in p_temp:
        print(city_temp[v]) v p_temp print(city_temp[v]) print city_temp[v] city_temp v city={} {} city S = input().split() input().split() S city_name=list(set(city_name)) list(set(city_name)) city_name p_temp = list(city_temp.keys()) list(city_temp.keys()) p_temp N = int(input()) int(input()) N city_name=[] [] city_name city_temp = {} {} city_temp
N = int(input())
city={}
city_name=[]
for n in range(N):
    S = input().split()
    city[n+1]=S
    city_name.append(S[0])

city_name=list(set(city_name))
city_name.sort()

for c_name in city_name:
    city_temp = {}
    for c_key in city.keys():
        if city[c_key][0] == c_name:
            city_temp[int(city[c_key][1])]=c_key
            
    p_temp = list(city_temp.keys())
    p_temp.sort(reverse=True)
    for v in p_temp:
        print(city_temp[v])