import scala.io.StdIn.readLine
import scala.collection.immutable.Queue
import scala.annotation.tailrec

object Main {
  @tailrec
  def loop(n:Int,q:Queue[(String,Int)]):Queue[(String,Int)] = {
    if(n==0) q
    else {
      val m = readLine.split(" ")
      loop(n-1,q.enqueue((m(0),m(1).toInt)))
    }
  }

  @tailrec
  def rrobin(q:Queue[(String,Int)],total:Int,qt:Int):Unit = {
    if(q.isEmpty) return
    else {
      val ((p,t),r) = q.dequeue
      val (newQ,newT) =
          if(t>qt) (r.enqueue((p,t-qt)),qt)
          else {
            println(p + " " + (t+total))
            (r,t)
          }
      rrobin(newQ,total+newT,qt)
    }
  }

  def main(args:Array[String]) = {
    val l = readLine.split(" ").map(_.toInt)
    val q = loop(l(0),Queue[(String,Int)]())

    rrobin(q,0,l(1))
  }
}