import qualified Data.Vector         as V
import qualified Data.Vector.Mutable as VM
import Control.Applicative
import Control.Monad
import Data.IORef

type Process = (String, Int)

roundRobin :: Int -> [Process] -> IO [Process]
roundRobin q xs = do
  queue <- V.thaw $ V.fromList xs
  state <- newIORef (1, 0, [])
  loop queue state
  (_, _, ys) <- readIORef state
  return (reverse ys)
    where
      len = length xs - 1
      loop vec st = do
        (flag, time, ys) <- readIORef st
        if flag == 0
          then return ()
          else do
          writeIORef st (0, time, ys)
          forM_ [0 .. len] $ \i -> do
            (p, t) <- VM.read vec i
            when (t > 0) $ do
              (flag, time, ys) <- readIORef st
              if t > q
                then do
                VM.write vec i (p, t - q)
                writeIORef st (flag + 1, time + q, ys)
                else do
                VM.write vec i (p, 0)
                writeIORef st (flag, time + t, (p, time + t) : ys)
          loop vec st

main :: IO ()
main = do
  [n, q] <- map read . words <$> getLine
  xs <- map (toTuple . words) <$> replicateM n getLine
  ys <- roundRobin q xs
  mapM_ (putStrLn . toString) ys
    where
      toTuple [n, t]  = (n, read t)
      toString (n, t) = unwords [n, show t]

