let () =
  let n,quantum = Scanf.scanf "%d %d\n" (fun a b -> a,b) in
  let q = Queue.create () in
  for i=1 to n do
    Queue.push (Scanf.scanf "%s %d\n" (fun a b -> a,b)) q
  done;
  let rec round_robin sum = match Queue.is_empty q with
      true -> ()
    | false ->
      match Queue.pop q with
        p,t when t <= quantum ->
        let s = sum + t in
        Printf.printf "%s %d\n" p s;
        round_robin s
      | p,t ->
        Queue.push (p,t-quantum) q;
        round_robin (sum+quantum)
  in
  round_robin 0