import Control.Monad
import Data.List
import Data.Ord

data Restaurant = Restaurant {number :: Int, city :: String, score :: Int}
  deriving (Show, Eq)

instance Ord Restaurant where
  compare r1 r2 = compare (city r1) (city r2) `mappend` compare (score r2) (score r1)

toRecords :: Int -> [[String]] -> [Restaurant]
toRecords _ [] = []
toRecords counter ([s1, s2]:xs) = Restaurant counter s1 (read s2):toRecords (counter + 1) xs

main :: IO ()
main = do
  n <- readLn
  input <- replicateM n $ words <$> getLine
  let list = toRecords 1 input
  mapM_ (print . number) $ sort list
