import scala.io.StdIn

object Main extends App {

  var head = 0
  var tail = 0
  
  val Array(n, q) = StdIn.readLine().trim.split(' ').map(_.toInt)
  val max  = n + 1 
  val myqueue: Array[ProceesInfo] = new Array[ProceesInfo](max)

  case class ProceesInfo(name: String, time: Int) 
  
  def isEmpty() = head == tail
  
  def isFull() = head == ((tail + 1) % max)
  
  def enqueue(p: ProceesInfo) = {
    if(isFull()) throw new RuntimeException
    else {
      myqueue(tail) = p
      if(tail + 1 == max){
        tail = 0
      } else {
        tail += 1
      }
    }
  }
  
  def dequeue(): ProceesInfo = {
    if(head == tail) throw new RuntimeException
    else {
      val ret = myqueue(head)
      if(head + 1 == max){
        head = 0
      } else {
        head += 1
      }
      ret
    }
  }
  
  (0 until n).foreach{ _ =>
    val Array(ename, etime) = StdIn.readLine().trim.split(' ')
    enqueue(ProceesInfo(ename, etime.toInt))
  }
  
  var executeTime: Int = 0
  while(head != tail){
    val current = dequeue()
    val remaintime = if((current.time - q) < 0) 0 else current.time - q
    
    executeTime  += (if((current.time - q) < 0) current.time else q)
    
    val executed = ProceesInfo(current.name, remaintime)  
    if(executed.time == 0){
      println(executed.name + " " + executeTime)
    } else {
      enqueue(executed)
    }
  }
  
}

