import scala.io.StdIn.readLine
import scala.reflect.ClassTag
case class Queue[T](len: Int)(implicit m: ClassTag[T]) {
    var que = m.newArray(len)
    var size = 0
    var headPtr = len - 1
    var tailPtr = len - 1
    
    def isEmpty(): Boolean = if (size == 0) true else false
    def isFull(): Boolean = if (len == size) true else false
    def enque(e: T): Unit = {
        if (!isFull) {
            size += 1
            que(headPtr) = e
            if (headPtr - 1 < 0) headPtr = len - 1
            else headPtr -= 1
        } else {
            throw new RuntimeException("error...")
        }
    }
    def deque(): T = {
        if (!isEmpty) {
            val ret = que(tailPtr)
            size -= 1
            if (tailPtr - 1 < 0) tailPtr = len - 1
            else tailPtr -=1
            ret
        } else {
            throw new RuntimeException("error...")
        }
    }
}
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] = new Queue[Proc](procNum)
        for (i <- (1 to procNum)) {
            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(total: Int, result: List[String]): List[String] = {
            if (que.isEmpty) result
            else {
                val (pProc, time) = que.deque.exec(quantum)
                if (pProc.finished) {
                    go(total + time, s"${pProc.name} ${total + time}" :: result)
                } else {
                    que.enque(pProc)
                    go(total + time, result)
                }
            }
        }
        go(0, Nil).reverse
    }
}
