import Control.Applicative

type Process = (String, Int)

process :: Int -> Int -> Process -> (Int, Process)
process quantum elapsed (name, time)
  | time <= quantum = (elapsed+time,    (name, 0))
  | otherwise       = (elapsed+quantum, (name, time-quantum))

processAndPrint :: Int -> Int -> [Process] -> IO ()
processAndPrint _ _ [] = return ()
processAndPrint quantum elapsed (p:ps) = do
  let (elapsed', p'@(name, time)) = process quantum elapsed p
  if time == 0
     then do
       putStrLn $ name ++ " " ++ show elapsed'
       processAndPrint quantum elapsed' ps
     else
       processAndPrint quantum elapsed' (ps ++ [p'])

main :: IO ()
main = do
  [n, q] <- map read . words <$> getLine :: IO [Int]
  processAndPrint q 0 =<< (getProcesses n)
  where
    getProcesses :: Int -> IO [Process]
    getProcesses 0 = return []
    getProcesses n = do
      [name, time] <- words <$> getLine
      processes    <- getProcesses (n-1)
      return $ (name, read time):processes

