import Data.List
import Data.Ord

main = do 
 _ <- getLine
 a <- map (map (read::String->Int) .words) .lines<$>getContents :: IO([[Int]])
 let a10 = zip a [1..]  :: [([Int],Int)]
 let sorted = sortBy (
              comparing (\e -> (head $ fst e)* 10^10 + (last $ fst e))) a10
              :: [([Int],Int)]
 let perfect= groupBy (\x y -> (head .fst $x) == (head .fst $ y)) sorted 
              ::[[([Int],Int)]] 
 mapM_ (putStrLn .snd)  .sortBy (comparing fst).concat.map f $ perfect

f :: [([Int],Int)] -> [(Int,String)] 
f part =zip (map snd part) (zero $ map (header * 10^6 +) [1..])
 where
   header = head .fst .head $ part

zero :: [Int] -> [String]
zero a = map (\part -> (concat $ replicate (12-(length .show $ part)) "0")++ show part) a