restaurant_num = gets.chomp.to_i

review_infos = {}

restaurant_num.times do |i|
  name, point = gets.chomp.split(' ')
  review_infos[name] ||= {}
  review_infos[name][i+1] = point.to_i
end

name_dic_order = review_infos.keys.sort
name_dic_order.each do |name|
  answers = review_infos[name].sort_by{|k, v| v}.reverse
  answers.each { |answer| puts answer.first }
end