import Data.Functor

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

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