import Control.Monad
import Data.Function
import Data.List
import Data.Ord

giveNumber :: [(Int, (Int, Int))] -> [(Int, (Int, Int))]
giveNumber = zipWith (\x (i, (p, y)) -> (i, (p, x))) [1..]

fillDigit6 :: Int -> String
fillDigit6 n = let s = show n in replicate (6 - length s) '0' ++ s

toId :: (Int, Int) -> String
toId (p, x) = fillDigit6 p ++ fillDigit6 x

main = do
    [_, m] <- map read . words <$> getLine
    ds <- replicateM m ((\[x, y] -> (x, y)) . map (read :: String -> Int) . words <$> getLine)
    mapM_ putStrLn $ map toId $ map snd $ sort $ concat $ map giveNumber $ groupBy ((==) `on` (fst . snd)) $ sortBy (comparing snd) $ zip [1..] ds