num = gets.to_i
cities = {}
num.times do |i|
  input_city_name, input_score = gets.split(" ")
  cities[input_city_name] ||= {}
  cities[input_city_name][input_score.to_i] = (i+1)
end

cities.keys.sort.each do |city_name|
  cities[city_name].sort{|(k1, _), (k2, _)| k2 <=> k1 }.to_h.each_pair do |score, rst|
    puts rst
  end
end