import std.stdio, std.string, std.conv, std.array, std.range, std.algorithm;

void main() {
    int n = readln.chomp.to!int;
    string[] a = new string[n];
    foreach (i; 0 .. n) {
        string[] tmp = readln.split;
        string s = tmp[0];
        int p = 100 - tmp[1].to!int;
        string t = rightJustify(p.to!string, 3, '0');
        a[i] = s ~ t;
    }
    int[] b = iota(1, n+1).array;
    zip(a, b).sort!((t1, t2) => t1[0] < t2[0]);
    foreach (x; b) {
        x.writeln;
    }
}