n = gets.chomp.to_i
rests = {}

n.times do |i|
  name,p = gets.chomp.split
  p = p.to_i
  rests.has_key?(name) ? 
    rests[name] << [i+1,p] :
  	rests[name]= [[i+1,p]]
end

rests.sort.each do |rest|
  result = rest[1].sort{|a, b| b[1] <=> a[1] }
  result.each{|re| p re[0]}
end

