import Control.Monad
import Data.Ord
import Data.List
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)
  let cs = [City i p y | (i,(p,y)) <- zip [1..] pys]
  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]
