import java.util.*
import java.math.*

fun main(args: Array<String>) {
//    var (r, d, x) = readLine()!!.split(" ").map { it.toInt() }
    var N = readLine()!!.toInt()
//    val S = readLine()!!.toInt()
//    val D = readLine()!!.split(" ").map { it.toLong() }
//    val A = readLine()!!.split(" ").map { it.toInt() }.toIntArray()
    val list = mutableListOf<Triple<String,Int,Int>>()
    for (i in 1 .. N) {
        var (s, p) = readLine()!!.split(" ")
        var pp = p.toInt()
        list.add(Triple(s,pp,i))
    }
    list.sortByDescending { it.second }
    list.sortBy { it.first }
    for  (l in list)
        println(l.third)
}
