conv ::	[[String]] -> [(String, Int)]
conv []	= []
conv ([a,b]:xs)	= (a, read b) :	conv xs

solve :: Int -> [(String, Int)] -> Int -> [String] -> [String]
solve _ [] _ list = list
solve q (all@(a,b):xs) time list
  | (b - q) <= 0 = solve q xs (time + b) ((a ++ " " ++ (show . (time +)) b):list)
  | otherwise = solve q (xs ++ (a, b - q):[]) (time + q) list

main = do
  ([_,qs]:xs) <- fmap (map words . lines) getContents
  mapM_ putStrLn $ reverse $ solve (read qs) (conv xs) 0 []
