fun main(args: Array<String>) {
    val N = readLine()!!.split(' ').map(String::toInt).first()
    val rs = (1..N).mapIndexed { index, i ->
        val (s, pts) = readLine()!!.split(' ')
        Triple(i, s, pts.toInt())
    }
    rs.sortedByDescending { it.third }.sortedBy { it.second }.forEach {println(it.first)}
}
