local function str2tbl(s)
    -- limit of #s is approximately 999959
    local t = {string.byte(s, 1, #s)}
    local char = string.char
    for i=1, #t do
        t[i] = char(t[i])
    end
    return t
end
--
local N = io.read("n", "l")
local restaurants = {}
for i=1,N do
    local tmp = io.read("l")
    local tbl = str2tbl(tmp)
    local s, p
    for j=1, #tbl do
        if tbl[j] == ' ' then
            s = string.sub(tmp, 1, j-1)
            p = tonumber(string.sub(tmp, j+1))
            break
        end
    end
    --print(s, p)
    table.insert(restaurants, {i, s, p})
end

table.sort(restaurants, function(x, y)
    if x[2] ~= y[2] then
        return x[2] < y[2]
    else
        return x[3] > y[3]
    end
end)
for i=1, N do
    print(restaurants[i][1])
end