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

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

f :: [(Prefecture, Year)] -> [String]
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..]

-- a :: Map (Prefecture

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