import scala.io.{StdIn => in}

object Main extends App {
  val n = in.readInt
  val s = Iterator.continually(in.readLine)
    .take(n)
    .map(_.split(" "))
    .map(_.toBuffer)
    .toArray

  for(i <- 1 to n) {
    s(i-1) :+= i.toString
  }

  val ss = s.sortBy(e => e(1).toInt * -1)
    .sortBy(e => e(0))
    .map(e => e(2))
    .map(s => s.toInt)

  println(ss.mkString("\n"))

}