n=io.read("*n","*l")
t={}
for i=1,n do
    x=io.read()
    s,p=x:match("(%w+) (%d+)")
    table.insert(t, {s,p,i})
end
table.sort(t,function(x,y)
    if x[1]~=y[1] then
        return x[1]<y[1]
    else
        return x[2]>y[2]
    end
end)
for i=1,n do
    print(t[i][3])
end