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

import qualified Data.Sequence       as S

solve :: Int
      -> Int
      -> [(String, Int)]
      -> S.Seq (String, Int)
      -> [(String, Int)]
solve q time result queue =
    case S.viewl queue of
        S.EmptyL -> result
        (s, t) S.:< xs
            | t <= q -> solve q (time + t) (result ++ [(s, time + t)]) xs
            | otherwise -> solve q (time + q) result (xs S.|> (s, t - q))

main :: IO ()
main = do
    [_, q] <- fmap read . words <$> getLine :: IO [Int]
    ts <- fmap ((\[a,b] -> (a, read b)) . words) . lines <$> getContents :: IO [(String, Int)]
    let answer = solve q 0 [] (S.fromList ts)
    mapM_ (\(n, t) -> printf "%s %d\n" n t) answer

