import Control.Monad
import Data.List

import           Data.Attoparsec.ByteString.Char8
import qualified Data.ByteString.Char8       as B
import qualified Data.Vector.Unboxed         as U
import qualified Data.Vector.Unboxed.Mutable as UM

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 f . zip [1..]
  where
    f (_, (s1, p1)) (_, (s2, p2)) = case compare s1 s2 of
      GT -> GT
      LT -> LT
      EQ -> compare p2 p1