let () =
  let (n:int),(quantum:int) = Scanf.scanf "%d %d\n" (fun a b -> a,b) in
  let (q:(string * int) Queue.t) = Queue.create () in
  for i=1 to n do
    Queue.push (Scanf.scanf "%s %d\n" (fun a b -> a,b)) q
  done;
  let (sum:int ref) = ref 0 in
  while not (Queue.is_empty q) do
    match Queue.pop q with
      p,t when t <= quantum ->
      sum := !sum + t;
      Printf.printf "%s %d\n" p !sum
    | p,t ->
      Queue.push (p,t-quantum) q;
      sum := !sum+quantum
  done