fun main(args : Array<String>) {
    val N = readLine()!!.toInt()
    val SAndP = mutableListOf<Triple<Int, String, Int>>()

    (1..N).forEach {
        val scanned = readLine()!!.split(" ")
        val s = scanned[0]
        val p = scanned[1].toInt()
        SAndP.add(Triple(it , s, p))
    }


    SAndP.sortBy { it.second }
    val grouped = SAndP.groupBy {
       it.second
    }

    grouped.entries.forEach {
        it.value.sortedBy { it.third * -1 }.forEach {
            println(it.first)
        }
    }
}