object Main extends App {
  val sc = new java.util.Scanner(System.in)
  (1 to sc.nextInt())
    .map(sc.next() -> sc.nextInt() -> _)
    .sortBy { case ((name, rate), _) => (name, -rate) }
    .foreach { case (_, i) => println(i) }
}
