import Text.Printf

ans q t [] oq = oq
ans q t iq@(i:is) oq =
  let (n,t') = i
  in
    if t' > q
    then ans q (t+q)  (is++[(n,t'-q)]) oq
    else ans q (t+t') is (oq++[(n,t+t')])

main = do
  l <- getLine
  c <- getContents
  let [n,q] = map read $ words l :: [Int]
      i = map (\[n, t] -> (n, read t)) $ map words $ lines c :: [(String,Int)]
      o = ans q 0 i []
  mapM_ (\ (n,t) -> printf "%s %d\n" n t ) o