import java.util.*
 
fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    (1..n).map { Triple(sc.next(), sc.nextInt(), it) }
        .sortedWith(Comparator { o1, o2 ->
            if (o1.first == o2.first) o2.second - o1.second
            else o1.first.compareTo(o2.first)
        }).forEach { println(it.third) }
}