n = gets.chomp
n = n.to_i
vals = []
(0..(n - 1)).each do |i|
  name_p = gets.chomp.split(" ")
  vals[i] = {name: name_p[0], p: name_p[1].to_i, idx: i + 1}
end

vals.sort! do |a, b|
  if a[:name] > b[:name]
    1
  elsif a[:name] < b[:name]
    -1
  else
    if a[:p] < b[:p]
      1
    else
      -1
    end
  end
end

vals.each do |val|
  puts val[:idx]
end
