import kotlin.comparisons.compareBy

fun main(arg: Array<String>) {
    val n = readLine()!!.toInt()
    (1..n).map {
        val (s, p) = readLine()!!.split(' ')
        Triple(s, p.toInt(), it)
    }.sortedWith(compareBy({ it.first }, { -it.second })).forEach { println(it.third) }
}
