data class Process(val id: String, val time: Int)

class Queue<T>(private val maxSize: Int) {

    private val elements = arrayListOf<T>()

    fun isEmpty() = elements.size == 0

    fun isFull() = elements.size == maxSize

    fun enqueue(element: T) {
        if (isFull()) throw Exception("error")
        elements.add(element)
    }

    fun dequeue(): T {
        if (isEmpty()) throw Exception("error")
        return elements.removeAt(0)
    }
}

fun main(args: Array<String>) {
    val (n, q) = readLine()!!.split(" ").map(String::toInt)
    val queue = Queue<Process>(n)
    (1..n).forEach {
        val (id, t) = readLine()!!.split(" ")
        queue.enqueue(Process(id, t.toInt()))
    }

    var count = 0
    while (!queue.isEmpty()) {
        val process = queue.dequeue()
        if (process.time <= q) {
            count += process.time
            val id = process.id
            println("$id $count")
        } else {
            queue.enqueue(Process(process.id, process.time - q))
            count += q
        }
    }
}
