let split str delim =
  let rec doit s acc =
    match
      try Some (String.rindex s delim) with _ -> None
    with
    | None -> 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 s1 (s2 :: acc)
  in
  doit str []

let () =
  let open Queue in
  let (que : (string * int) Queue.t) = create () in
  match List.map int_of_string (split (read_line ()) ' ') with
  | [n; q] -> begin
      let rec read i =
        if i < n then begin
          match split (read_line ()) ' ' with
          | [s; t] -> (add (s, int_of_string t) que; read (i + 1))
          | _ -> exit 1
        end
      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 print_string s; print_char ' '; print_int x; print_char '\n'; doit x)
          else (add (s, rest) que; doit (cnt + q))
        end
      in
      doit 0
    end
  | _ -> exit 1