open Scanf
open Printf

type que = NULL | QUE of string * int * que
let n, b = scanf "%d %d\n" (fun x y -> (x, y))

let rec input q i =
 if i = n then q
 else
  let name, time = scanf "%s %d\n" (fun x y -> (x, y)) in
  match q with
  NULL -> input (QUE (name, time, NULL)) (i+1)
  |q' -> input (QUE (name, time, q')) (i+1)

let () =
 let rec f q1 q2 t =
  match q1 with
  NULL -> f q2 q1 t
 |QUE (name, time, q') -> 
  if time <= b then
   let t' = time + t in
   printf "%s %d\n" name t'; f q' q2 t'
  else
   f q' (QUE (name, time, q2)) (time+b)
 in
 f (input NULL 0) NULL 0