import Control.Monad
import Data.List
import Data.Function

main :: IO ()
main = do
  n <- readLn
  sps <- replicateM n $ (\[s, p] -> (s, read p)) . words <$> getLine
  mapM_ print $ solve sps

solve :: [(String, Int)] -> [Int]
solve = map fst . sortBy ((compare `on` fst) <> (flip compare `on` snd) `on` snd) . zip [1..]