import Control.Monad
import Control.Applicative

main :: IO ()
main = do
  [n, q] <- map read . words <$> getLine
  queue <- map ((\[x, y] -> (x, read y)) . words) <$> replicateM n getLine :: IO [(String, Int)]
  putStrLn . unlines $ calc queue q 0 []

calc :: [(String, Int)] -> Int -> Int -> [String] -> [String]
calc [] _ _ ans = reverse ans
calc ((name, time):xs) n total ans
  | time > n = calc (xs ++ [(name, time - n)]) n (total + n) ans
  | otherwise = calc xs n (total + time) $ (unwords [name, show $ total + time]) : ans

