let () =
  let open Queue in
  let (que : (string * int) Queue.t) = create () in
  let n, q = Scanf.scanf "%d %d\n" (fun n q -> n, q) in
  let rec read i =
    if i < n then (add (Scanf.scanf "%s %d\n" (fun s t -> s, t)) que; read (i + 1))
  in
  read 0;
  let rec doit cnt =
    if not (is_empty que) then begin
      let s, t = take que in
      let rest = t - q in
      if rest <= 0 then (let x = cnt + t in Printf.printf "%s %d\n" s x; doit x)
      else (add (s, rest) que; doit (cnt + q))
    end
  in
  doit 0