import           Control.Monad (replicateM)
import           Data.Function (on)
import           Data.List     (groupBy, sortBy, foldl', sortOn)
import           Data.Ord      (comparing)

import Data.IntMap.Strict (IntMap, alter, singleton, toAscList)
import qualified Data.IntMap.Strict as M (empty, insert)

main :: IO ()
main = do
  [_n, m] <- map read . words <$> getLine
  pys <- replicateM m $ (\[p, y] -> (p, y)) . map read . words <$> getLine
  mapM_ putStrLn $ f pys

type Prefecture = Int
type Year = Int
type City = Int

f :: [(Prefecture, Year)] -> [String]
f =
  map (\(i, p, j) -> pad6 (show p) ++ pad6 (show j)) .
  sortOn (\(i, p, j) -> i) .
  concatMap (zipWith (\j (i, (p, y)) -> (i, p, j)) [1..]) .
  groupBy ((==) `on` (\(i, (p, y)) -> p)) .
  sortOn snd .
  zip [1..]


-- f = undefined . fmap (map (\(j, (y, i)) -> (j, i)) . zip [1..] . toAscList) . makeMap

-- makeMap :: [(Prefecture, Year)] -> IntMap (IntMap City)
-- makeMap =
--   foldl' (\mp (i, (p, y)) -> alter (Just . maybe (singleton y i) (M.insert y i)) p mp) M.empty .
--   zip [1..]

{-
C022_scrambled 以降 TLE
f =
  map (\(i, p, j) -> pad6 (show p) ++ pad6 (show j)) .
  sortBy (comparing $ \(i, p, j) -> i) .
  concatMap (zipWith (\j (i, (p, y)) -> (i, p, j)) [1..]) .
  groupBy ((==) `on` (\(i, (p, y)) -> p)) .
  sortBy (comparing snd) .
  zip [1..]
-}

pad6 :: String -> String
pad6 = reverse . take 6 . (++ repeat '0') . reverse
