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

type Process = (String, Int)

roundRobin :: Int -> [Process] -> IO ()
roundRobin q xs = do
  queue <- V.thaw $ V.fromList (xs ++ [("String", 0)])
  front <- newIORef 0
  rear  <- newIORef $ length xs
  loop q 0 queue front rear
  where
    n = length xs
    loop q t queue front rear = do
      f <- readIORef front
      r <- readIORef rear
      when (f /= r) $ do
        i <- readIORef front
        writeIORef front (if i == n then 0 else i + 1)
        (name, time) <- VM.read queue i
        if time <= q
          then do
          printf "%s %d\n" name (t + time)
          loop q (t + time) queue front rear
          else do
          j <- readIORef rear
          writeIORef rear (if j == n then 0 else j + 1)
          VM.write queue j (name, time - q)
          loop q (t + q) queue front rear

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

