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 ++ [("dummy", 0)])
  loop 0 queue 0 n
  where
    n = length xs
    
    loop :: Int -> VM.IOVector (String, Int) -> Int -> Int -> IO ()
    loop t vec front rear = do
      when (front /= rear) $ do
        (name, time) <- VM.read vec front
        let front' = if front == n then 0 else front + 1
        if time <= q
          then do
          printf "%s %d\n" name (t + time)
          loop (t + time) vec front' rear
          else do
          VM.write vec rear (name, time - q)
          let rear' = if rear == n then 0 else rear + 1
          loop (t + q) vec 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)

