data class Restaurant(val id: Int, val city: String, val score: Int)

fun main(args: Array<String>) {
  val n = readLine()!!.toInt()
  val restaurants = Array(n, {
    val id = it + 1
    val tokens = readLine()!!.split(" ")
    Restaurant(id, tokens[0], tokens[1].toInt())
  })
  restaurants.sortByDescending { it.score }
  restaurants.sortBy { it.city }
  restaurants.forEach { println(it.id) }
}