fun main(args: Array<String>) {
    val n = readInputLine().toInt()
    
    val list = mutableListOf<Triple<Int, String, Int>>()
    
    for (i in 1..n) {
        val (s, p) = readInputLine().split(" ")
        list.add(Triple(i, s, p.toInt()))
    }
    
    list.sortByDescending{it.third}
    list.sortBy{it.second}
    
    for (l in list) {
        println(l.first)
    }
}
 
fun readInputLine(): String {
    return readLine()!!
}
