import Control.Applicative
import Control.Monad
import Text.Printf


type Process = (String, Int)

roundRobin :: Int -> Int -> [Process] -> [Process] -> [Process] -> [Process]
roundRobin q t [] []  ys = reverse ys
roundRobin q t [] xs' ys = roundRobin q t (reverse xs') [] ys
roundRobin q t ((name, time) : xs) xs' ys
  | time <= q = roundRobin q (t + time) xs xs' ((name, t + time) : ys)
  | otherwise = roundRobin q (t + q) xs ((name, time - q) : xs') ys

main :: IO ()
main = do
  [n, q] <- map read . words <$> getLine
  xs <- map (toTuple . words) <$> replicateM n getLine
  let ys = roundRobin q 0 xs [] []
  mapM_ (\(name, time) -> printf "%s %d\n" name time) ys
    where toTuple [n, t] = (n, read t)

