object Main {

  def main(args: Array[String]): Unit = {
    import scala.io.StdIn._

    val N = readLine().toInt
    val SP: Array[(Int, (String, Int))] = (0 until N). map { i =>
      val Array(s, p) = readLine().split(" ")
      (i+1, (s, p.toInt))
    }. toArray. sortBy(_._2)(Ordering.Tuple2(Ordering.String, Ordering.Int.reverse))

    // 市名を辞書順, 同じ市に複数レストラン
    SP.map(_._1).foreach(println)
  }
}