{-# LANGUAGE ViewPatterns #-}

import qualified Data.Sequence as S
import Data.Sequence (Seq, (|>), ViewL((:<)))

type Process = (String, Int)
readProc :: IO Process
readProc = do
  [name, stime] <- fmap words getLine
  return (name, read stime)

process :: Int -> Seq Process -> Int -> IO ()
process rtt ps' e = case S.viewl ps' of
  S.EmptyL -> return ()
  ((n, t) :< ps) ->
    if (t > rtt) then
      process rtt (ps |> (n,t-rtt)) (e + rtt)
    else do
      putStrLn $ n ++ " " ++ show (e+t)
      process rtt ps (e+t)

main :: IO ()
main = do
  [n, rtt] <- fmap (map read . words) getLine
  procs <- S.replicateM n readProc
  process rtt procs 0