module Main where
import Debug.Trace
import Data.List
import qualified Data.Sequence as S
import Data.Int
import Data.Char
import Data.Array
import Data.Maybe
-- import qualified Data.Map as M
import Data.Ord
import Control.Monad


solve :: Int -> Int -> [(String, Int)] -> [(String, Int)]
solve n qt l = sim 0 initialQueue where
    sim ct qu = case S.viewl qu of
        S.EmptyL -> []
        ((name, run) S.:< ps) -> if run > qt
                                    then sim (ct + qt) (ps S.|> (name, run - qt))
                                    else (name, ct + run):sim (ct + run) ps
    initialQueue = S.fromList l

readLine :: IO [Int]
readLine = fmap (map read . words) getLine

readLines :: Int -> IO [(String, Int)]
readLines n = replicateM n readTupple where
    readTupple = do 
        [name, stRun] <- fmap words getLine
        return (name, read stRun)

print' :: [(String, Int)] -> IO ()
print' [] = return ()
print' ((n, t):xs) = do
    putStrLn $ n ++ ' ':show t
    print' xs

main :: IO() 
main = do
    [n, q] <- readLine
    l <- readLines n
    print' $ solve n q l

