data class Process(val name: String, var time: Int)

fun main(args: Array<String>) {
    val n: Int
    val q: Int
    val input = readLine()
        ?.split(" ".toRegex())
    if (input != null) {
        n = input[0].toInt()
        q = input[1].toInt()
    } else {
        n = 0
        q = 0
    }
    val queue = MyQueue()
    repeat(n) {
        readLine()
            ?.split(" ")
            ?.let {
                queue.enqueue(Process(it[0], it[1].toInt()))
            }
    }
    val finishList = mutableListOf<String>()
    var totalTime = 0
    while (true) {
        try {
            val process = queue.dequeue()
            if (process.time <= q) {
                finishList.add("${process.name} ${totalTime + process.time}")
                totalTime += process.time
            } else {
                process.time -= q
                queue.enqueue(process)
                totalTime += q
            }
        } catch (e: Exception) {
            break
        }
    }
    println(finishList.joinToString("\n"))

}

class MyQueue {
    private val array = arrayOfNulls<Process>(100000)
    private var head = 0
    private var tail = 0

    fun enqueue(value: Process) {
        array[tail] = value
        tail = (tail + 1) % array.size
    }

    fun dequeue(): Process {
        val retVal = array[head]!!
        array[head] = null
        head = (head + 1) % array.size
        return retVal
    }
}
