local read = setmetatable({}, {__index = function(t, k) local a = {} for i=1,#k do table.insert(a, '*'..string.sub(k, i, i)) end local r = io.read local u = table.unpack or unpack return function() return r(u(a)) end end})
read.N = function(N) local t={} for i=1,N do t[i]=read.n() end return t end
local str2tbl = function(s) local t={} local u=string.sub for i=1,#s do t[i] = u(s, i, i) end return t end
string.split = function(s) local t={} for w in string.gmatch(s, "[^%s]+") do table.insert(t, w) end return (table.unpack or unpack)(t) end
--
local N = read.nl()
local cities = {}
for i=1,N do
    local s, p = read.l():split()
    p = tonumber(p)
    cities[s] = cities[s] or {}
    table.insert(cities[s], {i, p})
end

local cities2 = {}
for city in pairs(cities) do
    table.insert(cities2, city)
end
table.sort(cities2, function (x,y) return x<y end)

for _,cname in ipairs(cities2) do
    local city = cities[cname]
    table.sort(city, function (x,y) return x[2]>y[2] end)
    for _, r in ipairs(city) do
        print(r[1])
    end
end
