import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    (1..sc.nextInt()).map { Triple(it, sc.next(), sc.nextInt()) }.sortedBy { it.third }.reversed().sortedBy { it.second }.forEach { println(it.first) }
}