 n = gets.to_i

ary = []
 n.times do |i|
 c, s = gets.split
ary[i] = {number: i + 1, city: c, score: s.to_i*-1 }
end

arr = ary.sort_by! do |a|
    [a[:city], a[:score],]
    
end



arr.each do |a|
	 puts a[:number]
	end