n = gets.to_i
dict = []
for i in 1..n do
  s, p = gets.chomp.split
  dict.push([i, s, p.to_i])
end
dict.sort! { |e, f|
  if e[1] == f[1]
    -e[2] <=> -f[2]
  else
    e[1] <=> f[1]
  end
}
dict.each { |e|
  puts e[0]
}
