fun main(args:Array<String>) {
    val n = readLine()!!.toInt()
    val list = mutableListOf<Triple<String, Int, Int>>()
    for (i in 1..n) {
        val line = readLine()!!.split(" ")
        val s = line[0]
        val p = line[1].toInt()
        list.add(Triple(s, p, i))
    }
    val result = mutableListOf<Triple<String,Int,Int>>()
    result.add(list[0])
    loop@for(l in 1..list.size-1){
        for (i in 0..result.size-1) {
            if(list[l].first.compareTo(result[i].first)<0){
                result.add(i,list[l])
                continue@loop
            }else if(list[l].first.compareTo(result[i].first)==0){
                if(list[l].second>result[i].second){
                    result.add(i,list[l])
                    continue@loop
                }
            }
        }
        result.add(list[l])
    }
    result.forEach { println(it.third) }
}