import Control.Monad
import Control.Applicative

import qualified Data.Sequence as S

type Process = (String, Int)

process :: Int -> Int -> Process -> (Int, Process)
process quantum elapsed (name, time)
  | time <= quantum = (elapsed+time,    (name, 0))
  | otherwise       = (elapsed+quantum, (name, time-quantum))

processAndPrint :: Int -> Int -> S.Seq Process -> IO ()
processAndPrint quantum elapsed ps =
  case S.viewl ps of
    S.EmptyL     -> return ()
    (p S.:< ps') ->
      let
        (elapsed', p'@(name, time)) = process quantum elapsed p
      in
        if time == 0
           then do
             putStrLn $ name ++ " " ++ show elapsed'
             processAndPrint quantum elapsed' ps'
           else
             processAndPrint quantum elapsed' (ps' S.|> p')

main :: IO ()
main = do
  [n, q] <- map read . words <$> getLine :: IO [Int]
  processes <- replicateM n readProcess
  processAndPrint q 0 (S.fromList processes)
  where
    readProcess :: IO Process
    readProcess = do
      [name, time] <- words <$> getLine
      return (name, read time)

