n = gets.to_i
array = []

n.times.with_index do |i|
  c, p = gets.split(' ')
  array << {order: i, city: c, point: p.to_i }
end

array.sort! do |a,b|
  if a[:city] == b[:city]
    b[:point] <=> a[:point]
  else
    a[:city] <=> b[:city]
  end
end

array.each {|arr| puts arr[:order]+1}
