fun main(arr: Array<String>) {
    val n = readLine()!!.toInt()
    val sp = (1..n).map { Pair(it, readLine()!!.split(" ").let { Pair(it[0], it[1].toInt()) }) }.sortedWith(Comparator { t, t2 -> if(t.second.first == t2.second.first) t.second.second.compareTo(t2.second.second) * -1 else t.second.first.compareTo(t2.second.first)})
    sp.forEach { println(it.first) }
}
