import scala.io.StdIn.readLine
import scala.collection.mutable.Queue

object Main extends App {
  val l = readLine.split(" ").map(_.toInt)
  val q = new Queue[(String,Int)]
  var total = 0

  for(i<-0 until l(0)) {
    val m = readLine.split(" ")
    q += ((m(0), m(1).toInt))
  }

  while(!q.isEmpty) {
    val (p,t) = q.dequeue
    if(t>l(1)) {
      q += ((p,t-l(1)))
      total += l(1)
    } else {
      println(p + " " + (t+total))
      total += t
    }
  }
}