import Control.Applicative
import Control.Monad
import Data.List

main = do
  n <- (read::String -> Int) <$> getLine
  arr <- forM [1..n] (\i -> do
              params <- words <$> getLine
              let point = (read::String -> Int) $ params !! 1
              return (params !! 0, point, i))
  let lists = map third $ sortBy myCompare arr
  forM_ lists print

myCompare::(String, Int, Int) -> (String, Int, Int) -> Ordering
myCompare (a1, b1, c1) (a2, b2, c2) = case compare a1 a2 of
                                        LT -> LT
                                        EQ -> compare b2 b1
                                        GT -> GT

third::(String, Int, Int) -> Int
third (_, _, x) = x

