import Control.Monad

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

process :: Int -> [Process] -> Int -> IO ()
process _ [] _ = return ()
process rtt ((n, t):ps) e =
  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 <- replicateM n readProc
  process rtt procs 0