import java.util.ArrayDeque

fun main(args: Array<String>){
    val (n, q) = readLine()!!.split(' ').map{ it.toInt() }
    val queue = ArrayDeque<Pair<String, Int>>()
    repeat(n){
        val (a, b)  = readLine()!!.split(' ')
        queue.addLast(Pair(a, b.toInt()))
    }
    var time = 0
    while(queue.size >0){
        val task = queue.removeFirst()
        if (task.second <= q){
            time += task.second
            println("${task.first} ${time}")
        }else{
            time += q
            queue.addLast(Pair(task.first, task.second - q))
        }
    }
}

