import java.util.Scanner

case class Proc(name: String, time: Int)

object Main extends App {
  val sc = new Scanner(Console.in)

  def next() = sc.next
  def nextInt() = next.toInt

  val n = nextInt
  val q = nextInt

  val procs = List.fill(n)(Proc(next, nextInt))

  def schedule(in: List[Proc], out: List[Proc], totalTime: Int, log: List[Proc]): List[Proc] = {
    if (in.isEmpty) {
      if (out.isEmpty)
        log.reverse
      else
        schedule(out.reverse, List(), totalTime, log)
    } else {
      val Proc(name, t) = in.head
      if (t <= q)
        schedule(in.tail, out, totalTime + t, Proc(name, totalTime + t)::log)
      else
        schedule(in.tail, Proc(name, t - q)::out, totalTime + q, log)
    }
  }

  val log = schedule(procs, List(), 0, List())
  for (Proc(name, time) <- log)
    println(s"$name $time")
}

