import Control.Applicative
import Control.Monad

type Entry = (String, Int)
type Queue = [Entry]

main :: IO ()
main = do
  [n, q] <- map read . words <$> getLine :: IO [Int]
  qs <- replicateM n getEntry
  mapM_ (putStrLn . entry2str) $ solve qs q 

entry2str :: Entry -> String
entry2str (name, t) = name ++ " " ++ show t

getEntry :: IO Entry
getEntry = do
  [name, time] <- words <$> getLine
  return (name, read time)

solve :: Queue -> Int -> Queue
solve qs limit = go qs 0
  where
    go [] _ = []
    go ((name, t):xs) crr
      | t <= limit = let crr' = crr + t in
                       (name, crr') : go xs crr'
      | otherwise = let crr' = crr + limit in
                       go (xs ++ [(name, t - limit)]) crr' 