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 Evaluation(num: Int, city: String, score: Int)

  def solve(sc: Scanner): String = {
    val n = sc.nextInt()
    val evaluations = IndexedSeq.fill(n)((sc.next(), sc.nextInt())).zipWithIndex.map { case ((s, p), i) => Evaluation(i + 1, s, p) }
    debug(n, evaluations)

    val cities = evaluations.map(_.city).sorted.distinct

    cities.foldLeft(ArrayBuffer.empty[Int]) { (acc, city) =>
      evaluations.filter(_.city == city).sortBy(_.score).reverse.foreach { evaluation =>
        acc += evaluation.num
      }
      acc
    }.mkString("\n")
  }

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