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)]
  val b = new StringBuilder

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

  def rrobin(total:Int):Unit = {
    if(q.isEmpty) return
    else {
      val (p,t) = q.dequeue
      val newTotal =
        if(t>l(1)) {
          q += ((p,t-l(1)))
          total + l(1)
        } else {
          b.append(p + " " + (t+total)+"\n")
          total + t
        }
      rrobin(newTotal)
    }
  }

  rrobin(0)
  print(b.result)
}