import qualified Data.ByteString.Char8 as B
import qualified Data.Map as MP
import qualified Data.Vector.Unboxed as VU
import Data.Char
import Data.List

toTuple :: B.ByteString -> (Int, Int)
toTuple bs =
    let
        Just (a, bs') = B.readInt bs
        Just (b, _) = B.readInt $ B.dropWhile isSpace bs'
    in
        (a, b)

make :: MP.Map Int [Int] -> (Int, Int) -> MP.Map Int [Int]
make m (a,b) =
    case MP.lookup a m of
        Just _ -> MP.adjust (b:) a m
        Nothing -> MP.insert a [b] m

rebuild :: MP.Map Int [Int] -> MP.Map Int (VU.Vector Int) -> MP.Map Int (VU.Vector Int)
rebuild m n
    | MP.null m = n
    | otherwise = rebuild m' (MP.insert i xs' n)
        where
            ((i,xs),m') = MP.deleteFindMin m
            xs' = VU.fromList $ sort xs

lowerBound :: VU.Vector Int -> (Int, Int) -> Int -> Int
lowerBound vec (from, to) target
    | from == to = from
    | mValue >= target = lowerBound vec (from, mid) target
    | mValue < target = lowerBound vec (mid + 1, to) target
        where
            mid = (from + to) `quot` 2
            mValue = vec VU.! mid

comp :: Int -> String
comp n = zero ++ n'
    where
        n' = show n
        zero = replicate (6 - (length n')) '0'

main = do
    [n,m] <- map read . words <$> getLine
    xs <- VU.replicateM m (toTuple <$> B.getLine)
    let m = VU.foldl' make MP.empty xs
    let m' = rebuild m MP.empty
    VU.forM_ xs $ \(p,y) -> do
        let Just ys = MP.lookup p m'
        let lb = lowerBound ys (0, VU.length ys) y
        putStrLn $ comp p ++ comp (lb+1)