import Data.Functor((<$>))

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

solve :: [(String, Int)] -> [(String, Int)] -> [(String, Int)] -> Int -> Int -> [(String, Int)]
solve []            [] zs _ _   = reverse zs
solve []            ys zs q cnt = solve (reverse ys) [] zs q cnt
solve ((n, t) : xs) ys zs q cnt = let t'   = t - q
                                      cnt' = cnt + q
                                      m    = cnt' + t'
                                  in if t' > 0 then solve xs ((n, t') : ys) zs q cnt'
                                               else solve xs ys  ((n, m) : zs) q m