import scala.collection.mutable.Queue


object Main {
  def process(queue: Queue[(String, Int)], quantum: Int, elapse: Int = 0): Unit = {
    if (queue.length == 0) {
      return ()
    }

    val (name, last) = queue.dequeue
    val last2 = last - quantum
    if (last2 > 0) {
      queue += (name -> last2)
      process(queue, quantum, elapse + quantum)
    } else {
      println(s"$name ${elapse + last}")
      process(queue, quantum, elapse + last)
    }
  }

  def main(args: Array[String]) = {
    val Array(n, qua) = io.StdIn.readLine.split(" ").map(_.toInt)
    // println(n, qua)
    val queue = new Queue[(String, Int)]
    1 to n foreach { _ =>
      val Array(name, time) = io.StdIn.readLine.split(" ")
      queue += (name -> time.toInt)
    }
    // queue.foreach(println _)

    process(queue, qua)
  }
}

