import kotlin.comparisons.compareBy
import kotlin.comparisons.thenByDescending

fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    Array(N) { readLine()!!.split(" ").let { Pair(it[0], it[1]) } }.mapIndexed { i, p ->
        Triple(i + 1, p.first, p.second.toInt())
    }.sortedWith(compareBy<Triple<Int, String, Int>> { it.second }.thenByDescending { it.third })
        .joinToString(System.lineSeparator()) { it.first.toString() }
        .let(::println)
}