import           Data.List
import           Control.Applicative
import           Control.Monad
import           Control.Monad.State

prcs :: IO (String, Int)
prcs = do
  (nm : tm : _) <- words <$> getLine
  return (nm, read tm)

ex
  :: Int
  -> Int
  -> [(String, Int)]
  -> State ([String], [(String, Int)]) [(String, Int)]
ex q tms [] = do
  (rs, ts) <- get
  case ts of
    [] -> return []
    _  -> do
      put (rs, [])
      ex q tms (reverse ts)
ex q tms ((nm, tm) : ts)
  | q < tm = do
    (rs, sts) <- get
    put (rs, (nm, tm - q) : sts)
    ex q (tms + q) ts
  | otherwise = do
    (rs, sts) <- get
    put ((nm ++ " " ++ show (tms + tm)) : rs, sts)
    ex q (tms + tm) ts

main = do
  (n : q : _) <- map read . words <$> getLine
  ts          <- replicateM n prcs
  mapM_ putStrLn (reverse $ fst $ execState (ex q 0 ts) ([], []))
