import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import Data.Ord

main :: IO ()
main = readLn >>= flip replicateM getLine >>= printRes . solve
    where
        printRes = mapM_ print

solve :: [String] -> [Int]
solve = map fst . sortBy cmpf . map edit . zip [1..]
    where
        cmpf lhs rhs = comparing (fst . snd) lhs rhs `mappend` comparing (snd . snd) rhs lhs
        edit (i, xs) = (i, (s, read p :: Int))
            where
                [s, p] = words xs

readLine :: IO [Int]
readLine = unfoldr (fmap (second (maybe B.empty snd . B.uncons)) . B.readInt) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine