class Restorant
  attr_accessor :id, :city, :score
  def initialize(id, city, score)
    @id = id
    @city = city.to_s
    @score = score.to_i
  end

  def to_s
    "#{@id} #{@city} #{@score}"
  end

  def compare_to(res)
    return res.score <=> @score if @city == res.city
    @city <=> res.city
  end
end

N = gets.chop.to_i
restorants = []
N.times do |n|
  line = gets.chop.split
  restorants.push(Restorant.new(n + 1, line[0], line[1]))
end

restorants.sort! { |a, b| a.compare_to(b) }

restorants.each do |r|
  puts r.id
end