import collection.mutable.Queue


object Main {
  case class Task(name: String, time: Int)

  def main(args: Array[String]): Unit = {
    val tasks = Queue[Task]()

    val sc = new java.util.Scanner(System.in);
    val n = sc.nextInt
    val q = sc.nextInt

    for (_ <- 1 to n) tasks += Task(sc.next, sc.nextInt)

    var time = 0

    while (tasks.nonEmpty) {
      val task = tasks.dequeue
      if (task.time > q) {
        time = time + q
        tasks += task.copy(time = task.time - q)
      } else {
        time = time + task.time
        println(s"${task.name} $time")
      }
    }
  }
}