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)]
ex _ _ [] = return []
ex q tms ((nm, tm) : ts)
  | q < tm = ex q (tms + q) (ts ++ [(nm, tm - q)])
  | otherwise = do
    modify ((nm ++ " " ++ show (tms + tm)) :)
    ex q (tms + tm) ts

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

