import Data.Functor((<$>))
import Text.Printf(printf)

main :: IO ()
main = do 
        q  <- (read :: String -> Int).last.words <$> getLine
        xs <- map ((\[n, t] -> (n, (read :: String -> Int) t)).words).lines <$> getContents
        solve xs [] q 0

solve                     :: [(String, Int)] -> [(String, Int)] -> Int -> Int -> IO ()
solve []            []  _ _  = return ()
solve []            ys q cnt = solve (reverse ys) [] q cnt 
solve ((n, t) : xs) ys q cnt = let t'   = t - q
                                   cnt' = cnt + q
                                   m    = cnt' + t'
                               in if t' > 0 then solve xs ((n, t') : ys) q cnt'
                                            else printf"%s %d\n" n m >> solve xs ys q m