function main(input) {
    var rows = input.split("\n");
    rows.shift();
    rows.map(function (r, i) {
        var c = r.split(" ");
        return {
            id: i,
            name: c[0],
            score: c[1]
        };
    }).sort(function (a, b) {
        return b.score - a.score;
    }).sort(function (a, b) {
        if (a.name < b.name) return -1;
        if (a.name > b.name) return 1;
        return 0;
    }).map(function (c, i) {
        c.rank = i + 1;
        return c;
    }).sort(function (a, b) {
        return a.id - b.id;
    }).forEach(function (c) {
        console.log(c.rank);
    });
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));