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)] -> Int -> Int -> IO ()
solve []            _ _   = return ()
solve ((n, t) : xs) q cnt = let t'   = t - q
                                cnt' = cnt + q
                                m    = cnt' + t'
                            in if t' > 0 then solve (xs ++ [(n, t')]) q cnt'
                                         else printf "%s %d\n" n m >> solve xs q m