import scala.io.StdIn.readLine
case class Queue[T](in: List[T], out: List[T]) {
    def isEmpty(): Boolean = if (in.isEmpty && out.isEmpty) true else false
    def head(): T = out match {
        case x :: xs => x
        case _ => throw new RuntimeException("error...")
    }
    def enque(e: T): Queue[T] = {
        val newIn = e :: in
        new Queue[T](newIn, newIn.reverse)
    }
    def deque(): Queue[T] = out match {
        case x :: xs => new Queue[T](xs.reverse, xs)
        case _ => throw new RuntimeException("error...")
    }
}
object Queue {
    def apply[T](): Queue[T] = new Queue[T](Nil, Nil)
}
case class Proc(name: String, time: Int) {
    def exec(t: Int): (Proc, Int) = {
        if (time - t < 0) (new Proc(name, 0), time)
        else (new Proc(name, time - t), t)
    }
    def finished(): Boolean = if (time == 0) true else false
}
object Main {
    def main(args: Array[String]): Unit = {
        val line = readLine.split(" ").map(_.toInt)
        val procNum = line(0)
        val quantum = line(1)
        val que: Queue[Proc] = (1 to procNum).foldLeft(Queue[Proc]()) { (que, a) => 
            val p = readLine.split(" ")
            que.enque(new Proc(p(0), p(1).toInt))
        }
        println(process(que, quantum).mkString("\n"))
    }
    
    def process(que: Queue[Proc], quantum: Int): List[String] = {
        def go(que: Queue[Proc], total: Int, result: List[String]): List[String] = que match {
            case que if que.isEmpty => result
            case que => que.head.exec(quantum) match {
                case (pProc, time) if pProc.finished => go(que.deque, total + time, s"${pProc.name} ${total + time}" :: result)
                case (pProc, time) => go(que.deque.enque(pProc), total + time, result)
            }
        }
        go(que, 0, Nil).reverse
    }
}
