{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Ord
import Data.List
import qualified Data.IntMap.Strict as M
import Text.Printf

data City = City
  { cityId :: Int
  , pref :: Int
  , year :: Int
  }

main :: IO ()
main = do
  [n,m] <- getInts
  pys <- replicateM m $ do
    [p,y] <- getInts
    return (p,y)
  -- putStr . unlines $ solve pys
  let cs = [City i p y | (i,(p,y)) <- zip [1..] pys]
  putStr . unlines $ solve cs
  -- mapM_ (putStrLn . format) $ solve cs

getInts :: IO [Int]
getInts = map read . words <$> getLine

format :: (Int,Int) -> String
format (p,i) = printf "%06d%06d" p i

-- solve :: [City] -> [(Int,Int)]
-- solve = sortByID . concatMap sortByYear . groupByPref

-- groupByPref :: [City] -> [[City]]
-- groupByPref = groupBy (\x y -> pref x == pref y) . sortBy (comparing pref)

-- sortByYear :: [City] -> [(Int,Int,Int)]
-- sortByYear = zipWith (\i c -> (cityId c, pref c, i)) [1..] . sortBy (comparing year)

-- sortByID :: [(Int,Int,Int)] -> [(Int,Int)]
-- sortByID xs = [(p,i) | (_,p,i) <- sort xs]

solve :: [City] -> [String]
solve cs = [format (pref c,i) | (c,i) <- sortBy (comparing (cityId.fst)) cs'']
  where
    cs' = sortBy (comparing year) cs
    cs'' = ranking cs'

ranking :: [City] -> [(City,Int)]
ranking cs = count M.empty cs
  where
    count _ [] = []
    count !tbl (c:res) = (c,1 + f tbl c):(count (update c tbl) res)

    f tbl c = M.findWithDefault 0 (pref c) tbl

    update c tbl = M.insertWith (+) (pref c) 1 tbl
