def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n = i()
s = {}
for i in range(n):
	S,P = map(str,input().split())
	s[i+1] = [S, -int(P)]

note = sorted(s.items(), key=lambda x: x[1][0])
note.append( (10, ["LOL", 10] ) )
memo = note[0][1][0]
a = []
for i in note:
	if memo != i[1][0]:
		memo = i[1][0]
		a = sorted(a, key=lambda x: x[1][1])
		for j in range(len(a)):
			print(a[j][0])
		a = []
		a.append(i)
	else:
		a.append(i) def i():
	return int(input()) i return int(input()) int(input()) int input() input def i2():
	return map(int,input().split()) i2 return map(int,input().split()) map(int,input().split()) map int input().split() ().split () input split def s():
	return str(input()) s return str(input()) str(input()) str input() input def l():
	return list(input()) l return list(input()) list(input()) list input() input def intl():
	return list(int(k) for k in input().split()) intl return list(int(k) for k in input().split()) list(int(k) for k in input().split()) list int(k) int k n = i() n i() i s = {} s {} for i in range(n):
	S,P = map(str,input().split())
	s[i+1] = [S, -int(P)] i range(n) range n S,P = map(str,input().split()) S map(str,input().split()) map str input().split() ().split () input split P s[i+1] = [S, -int(P)] s[i+1] s i+1 i 1 [S, -int(P)] S -int(P) int(P) int P note = sorted(s.items(), key=lambda x: x[1][0]) note sorted(s.items(), key=lambda x: x[1][0]) sorted s.items() s.items s items key=lambda x: x[1][0] key lambda x: x[1][0] x[1][0] [1] x 1 0 x note.append( (10, ["LOL", 10] ) ) note.append note append (10, ["LOL", 10] ) 10 ["LOL", 10] "LOL" 10 memo = note[0][1][0] memo note[0][1][0] [1] [0] note 0 1 0 a = [] a [] for i in note:
	if memo != i[1][0]:
		memo = i[1][0]
		a = sorted(a, key=lambda x: x[1][1])
		for j in range(len(a)):
			print(a[j][0])
		a = []
		a.append(i)
	else:
		a.append(i) i note if memo != i[1][0]:
		memo = i[1][0]
		a = sorted(a, key=lambda x: x[1][1])
		for j in range(len(a)):
			print(a[j][0])
		a = []
		a.append(i)
	else:
		a.append(i) memo != i[1][0] memo i[1][0] [1] i 1 0 memo = i[1][0] memo i[1][0] [1] i 1 0 a = sorted(a, key=lambda x: x[1][1]) a sorted(a, key=lambda x: x[1][1]) sorted a key=lambda x: x[1][1] key lambda x: x[1][1] x[1][1] [1] x 1 1 x for j in range(len(a)):
			print(a[j][0])
		 j range(len(a)) range len(a) len a print(a[j][0]) print a[j][0] [j] a j 0 a = [] a [] a.append(i) a.append a append i a.append(i) a.append a append i note = sorted(s.items(), key=lambda x: x[1][0]) sorted(s.items(), key=lambda x: x[1][0]) note a = [] [] a def i():
	return int(input()) def i():
	return int(input()) i def i2():
	return map(int,input().split()) def i2():
	return map(int,input().split()) i2 def intl():
	return list(int(k) for k in input().split()) def intl():
	return list(int(k) for k in input().split()) intl s = {} {} s memo = note[0][1][0] note[0][1][0] memo a = [] [] a def l():
	return list(input()) def l():
	return list(input()) l S,P = map(str,input().split()) map(str,input().split()) S n = i() i() n def s():
	return str(input()) def s():
	return str(input()) s a = sorted(a, key=lambda x: x[1][1]) sorted(a, key=lambda x: x[1][1]) a P = map(str,input().split()) map(str,input().split()) P memo = i[1][0] i[1][0] memo
def i():
	return int(input())
def i2():
	return map(int,input().split())
def s():
	return str(input())
def l():
	return list(input())
def intl():
	return list(int(k) for k in input().split())

n = i()
s = {}
for i in range(n):
	S,P = map(str,input().split())
	s[i+1] = [S, -int(P)]

note = sorted(s.items(), key=lambda x: x[1][0])
note.append( (10, ["LOL", 10] ) )
memo = note[0][1][0]
a = []
for i in note:
	if memo != i[1][0]:
		memo = i[1][0]
		a = sorted(a, key=lambda x: x[1][1])
		for j in range(len(a)):
			print(a[j][0])
		a = []
		a.append(i)
	else:
		a.append(i)