function Main(input) {
    input = input.trim().split("\n");
    var N = parseInt(input[0],10);

    var tmp = [];
    for(var i = 0; i < N; i++){
        tmp[i] = input[i+1].split(" ")[0] + (999 - parseInt(input[i+1].split(" ")[1],10)) + "," + (i+1);
    }
    tmp.sort();

    for(var i = 0; i < N; i++){
        console.log(tmp[i].split(",")[1]);
    }
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));