import           Control.Applicative
import           Control.Monad
import qualified Data.ByteString.Char8 as B
import           Debug.Trace

readInt' :: B.ByteString -> Int
readInt' bs | Just (n, _) <- B.readInt bs = n

data Queue a =
    Queue [a]
          [a]
    deriving (Show)

enqueue :: a -> Queue a -> Queue a
enqueue x (Queue fs bs) = Queue fs (x:bs)

dequeue :: Queue a -> Maybe (a, Queue a)
dequeue (Queue [] []) = Nothing
dequeue (Queue [] (b:bs))
    | (c:cs) <- reverse (b : bs) = Just (c, Queue cs [])
dequeue (Queue (f:fs) bs) = Just (f, Queue fs bs)

isEmpty :: Queue a -> Bool
isEmpty (Queue [] []) = True
isEmpty _             = False

fromList :: [a] -> Queue a
fromList xs = Queue xs []

solve :: Int -> Queue (B.ByteString, Int) -> IO ()
solve quontum queue = go 0 queue
  where
    go c que =
        case dequeue que of
            Nothing -> return ()
            Just ((name, time), que') -> do
                if time <= quontum
                    then do
                        putStrLn $ B.unpack name ++ " " ++ show (c + time)
                        go (c + time) que'
                    else do
                        go (c + quontum) (enqueue (name, time - quontum) que')

main :: IO ()
main = do
    [n, q] <- fmap readInt' . B.words <$> B.getLine
    ps <- fmap ((\[a, b] -> (a, readInt' b)) . B.words)
          . B.lines <$> B.getContents
    let que = fromList ps
    solve q que

