"use strict"
function main(arg) {
    arg = arg.trim().split("\n")
    var N = Number(arg.shift())
    var data = []
    for (var i = 0; i < arg.length; i++) {
        var row = arg[i].split(" ")
        var n = (100 - Number(row[1]))
        var n_str = ''
        if (n < 10) {
            n_str = '0' + n
        } else {
            n_str = n
        }
        data.push(
            row[0] + n_str + "_" + Number(i + 1)
        )
    }
    data.sort()
    for (var i = 0; i < data.length; i++) {
        var id = data[i].split("_")[1]
        console.log(id)
    }
    console.log(JSON.stringify(data, null, "\t"))
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));