let () =
  let nq = read_line () |> Str.split (Str.regexp " ")
         |> List.map int_of_string |> Array.of_list in
  let (n,q) = (nq.(0), nq.(1)) and
      queue = Queue.create () in
  let rec read = function
      0 -> ()
    | i ->
       let line = read_line () |> Str.split (Str.regexp " ")
                  |> Array.of_list in
       Queue.push (line.(0),int_of_string line.(1)) queue;
       read (i-1)
  in
  read n;
  let rec f time_total =
    if Queue.is_empty queue then ()
    else
      let (name, time) = Queue.pop queue in
      if time <= q then
        begin
          Printf.printf "%s %d\n" name (time+time_total);
          f (time+time_total)
        end
      else
        begin
          Queue.push (name, (time-q)) queue;
          f (q+time_total)
        end
  in
  f 0;;