fun main(arr:Array<String>) {
    val n = readLine()!!.toInt()
    val restaurants = (1..n).map {id-> readLine()!!.split(" ").let { Restaurant(id, it[0], it[1].toInt()) } }.sorted()
    restaurants.forEach { println(it.id)}
}

class Restaurant(val id:Int, val city:String, val score:Int):Comparable<Restaurant> {
    override fun compareTo(other: Restaurant): Int {
        if(city == other.city) {
            return score.compareTo(other.score) * -1
        }
        return city.compareTo(other.city)
    }
}
