let split str delim =
  let rec doit s acc =
    match
      try Some (String.index s delim)
      with _ -> None
    with
    | None -> List.rev (s :: acc)
    | Some i ->
        let s1 = String.sub s 0 i in
        let s2 = String.sub s (i + 1) (String.length s - String.length s1 - 1) in
        doit s2 (s1 :: acc)
  in
  doit str []

let print_result = List.iter (fun (s, t) -> Printf.printf "%s %d\n" s t)

let () =
  match List.map int_of_string (split (read_line ()) ' ') with
  | [] | [_] -> exit 1
  | n :: q :: _ -> begin
      let que = Queue.create () in
      let rec read i =
        if i >= n then ()
        else begin
          match split (read_line ()) ' ' with
          | [] | [_] -> exit 1
          | s :: t :: _ -> (Queue.add (s, int_of_string t) que; read (i + 1))
        end
      in
      read 0;
      let rec doit cnt ret =
        if Queue.is_empty que then List.rev ret
        else begin
          let (s, t) = Queue.take que in
          let rest = t - q in
          if rest > 0 then (Queue.add (s, rest) que; doit (cnt + q) ret)
          else let x = cnt + t in doit x ((s, x) :: ret)
        end
      in
      print_result (doit 0 [])
    end