object Main extends App {
  val n = io.StdIn.readLine().toInt
  var seq = Seq[(String, Int, Int)]()
  for {i <- 1.to(n)} {
    val Array(s, p) = io.StdIn.readLine().split(" ")
    seq :+= (s, p.toInt, i)
  }
  seq.sortWith((i, j) => {
    if (i._1 != j._1) {
      i._1 < j._1
    } else {
      i._2 > j._2
    }
  }).foreach(i => println(i._3))
}