input = readlines()

cities = {}
rates = {}
n = input.shift.chomp.to_i
input.each_with_index do |l, i|
  city, rate = l.chomp.split("\s")
  rate = rate.to_i
  cities[city] = [] if cities[city].nil?
  cities[city].push(i + 1)
  rates[i + 1] = rate
end

cities.keys.sort.each do |city|
  tmp = []
  list = cities[city].sort_by{|x| rates[x]}
  puts list.reverse().join("\n")
end
