import java.util.Scanner

import scala.collection.mutable.ArrayBuffer

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)
    val writer = new java.io.PrintWriter(System.out)
    writer.println(solve(sc))
    writer.flush()
  }

  case class Restaurant(num: Int, city: String, score: Int)

  def solve(sc: Scanner): String = {
    val n = sc.nextInt()
    val evaluations = Vector.fill(n)((sc.next(), sc.nextInt())) // (市名, 評価点)
    val restaurants = evaluations.zipWithIndex.map { case ((city, score), i) => Restaurant(i + 1, city, score) }
    debug(n, evaluations)

    val cities = evaluations.map(_._1).sorted.distinct // Vector(kazan, khabarovsk, moscow)

    val restaurantNumBuf = ArrayBuffer.empty[Int]

    cities.foreach { city =>
      restaurants.filter(_.city == city).sortBy(_.score).reverse.foreach { restaurant =>
        restaurantNumBuf += restaurant.num
      }
    }
    debug(restaurantNumBuf)

    restaurantNumBuf.mkString("\n")
  }

  private def debug(x: Any): Unit = {
    if (System.getenv("LOCAL_DEBUG") != null) println(x)
  }
}
