fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val list: MutableList<Triple<String, Int, Int>> = java.util.ArrayList()
    for (i in 1..N) {
        val (S, Pstr) = readLine()!!.split(" ")
        val P = Pstr.toInt()
        list.add(Triple(S, P, i))
    }
    val list2 = list.sortedWith(java.util.Comparator { o1, o2 ->
        val res1 = o1.first.compareTo(o2.first)
        if (res1 != 0) {
            return@Comparator res1
        }
        return@Comparator -o1.second.compareTo(o2.second)
    })
    for (i in 0 until N) {
        if (i == N - 1) print(list2[i].third)
        else println(list2[i].third)
    }
}