import scala.io.StdIn.readLine

object Main extends App {
  val Array(n, q) = readLine.split(" ").map(_.toInt)
  val queue = scala.collection.mutable.Queue[(String, Int)]()
  var spentTime = 0

  (0 until n).foreach { e =>
    val Array(name, timeToComplete) = readLine.split(" ")
    queue.enqueue(name -> timeToComplete.toInt)
  }

  while (queue.nonEmpty) {
    val (name, time) = queue.head
    if (time - q <= 0) {
      queue.dequeue()
      spentTime += time
      println(s"$name $spentTime")
    } else {
      spentTime += q
      queue.enqueue((name, time - q))
      queue.dequeue()
    }
  }
}

