var lines = [];

var readline = require('readline')
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});


rl.on('line', (x) => {
    lines.push(x)
});

rl.on('close', () => {
    var N = Number(lines[0]); lines.shift();
    var s = []; var p = [];

    for (var i = 0; i < N; i++) {
        var m = lines[i].split(" ");
        s.push([m[0], Number(m[1]), i]);
    }

    for (var i = 0; i < N; i++) {
        for (var j = 0; j < N - 1; j++) {
            var a = s[j][0]; var b = s[j + 1][0];
            var c = s[j][1]; var d = s[j + 1][1];
            var e = s[j][2]; var f = s[j + 1][2];

            if (a > b || (a === b && a.length > b.length)) {
                var y = b; s[j + 1][0] = a; s[j][0] = y;
                var z = d; s[j + 1][1] = c; s[j][1] = z;
                var w = f; s[j + 1][2] = e; s[j][2] = w;
            }
        }
    }

    for (var i = 0; i < N; i++) {
        for (var j = 0; j < N - 1; j++) {
            var a = s[j][1]; var b = s[j + 1][1];
            var c = s[j][0]; var d = s[j + 1][0];
            var e = s[j][2]; var f = s[j + 1][2];
            if (c !== d) { continue; }
            if (a < b || (a === b && a.length < b.length)) {
                var y = b; s[j + 1][1] = a; s[j][1] = y;
                var z = d; s[j + 1][0] = c; s[j][0] = z;
                var w = f; s[j + 1][2] = e; s[j][2] = w;
            }
        }
    }
    for (var i = 0; i < N; i++)
        console.log(s[i][2] + 1)

});