import qualified Data.ByteString.Char8 as BC
import Data.Maybe
import Control.Monad
import qualified Data.IntMap as IM
import Text.Printf
import Data.List

type Map = IM.IntMap Int

readIntsLines :: IO [[Int]]
readIntsLines = map (map (fst . fromJust . BC.readInt) . BC.words) . BC.lines <$> BC.getContents

get :: Int -> Map -> Int
get key m = fromMaybe 1 $ IM.lookup key m

set :: Int -> Int -> Map -> Map
set = IM.insert

solve :: [(Int, Int, Int)] -> Map -> [(Int, String)]
solve [] _ = []
solve ((i, p, y):pys) m = (i, result) : solve pys (set p (curr + 1) m)
  where curr = get p m
        result = printf "%06d" p ++ printf "%06d" curr

main :: IO ()
main = do
  getLine
  pys <- readIntsLines
  let year (_, _, y) = y
  let ds = sortOn year $ zipWith (\x y -> (x, head y, last y)) [1..] pys
  let result = map snd . sortOn fst $ solve ds IM.empty
  putStr $ unlines result