import qualified Data.List as L
import qualified Data.Map.Strict as Map


main = do
    getLine
    contents <- getContents
    let toPair = (\[a, b] -> (a, b)) . map read . words
    putStrLn . unlines . solve . map toPair . lines $ contents

-- |
-- >>> solve [(1, 32), (2, 63), (1, 12)]
-- ["000001000002","000002000001","000001000001"]
-- >>> solve [(2, 55), (2, 77), (2, 99)]
-- ["000002000001","000002000002","000002000003"]

solve :: [(Int, Int)] -> [String]
solve = map f . solve'
    where f n = let s = show n
                in  drop (7 - length s) ("00000" ++ s)

-- |
-- >>> buildMap [(1, 32), (2, 63), (1, 12)]
-- fromList [(1,[12,32]),(2,[63])]

-- |
-- >>> sortMap . buildMap $ [(1, 12), (2, 63), (1, 32)]
-- fromList [(1,[12,32]),(2,[63])]

buildMap :: [(Int, Int)] -> Map.Map Int [Int]
buildMap = Map.fromListWith (++) . map (\(k, v) -> (k, [v]))

sortMap :: Map.Map Int [Int] -> Map.Map Int [Int]
sortMap = Map.map L.sort

-- |
-- >>> solve' [(1, 32), (2, 63), (1, 12)]
-- [1000002,2000001,1000001]
-- >>> solve' [(2, 55), (2, 77), (2, 99)]
-- [2000001,2000002,2000003]

solve' :: [(Int, Int)] -> [Int]
solve' xs = map f xs
    where f (k, v) = case Map.lookup k m >>= L.elemIndex v of
              Just i -> k * 1000000 + i + 1
          m = sortMap . buildMap $ xs
