import java.util.*

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

fun run(queue: Queue<Process>, q: Int) {
    var time = 0
    while (queue.size > 0) {
        val process = queue.poll()
        if (process.time > q) {
            process.time -= q
            time += q
            queue.add(process)
        } else {
            time += process.time
            println("${process.name} ${time}")
        }
    }
}

fun main(args: Array<String>) {
    val scanner = Scanner(System.`in`)
    val n = scanner.nextInt()
    val q = scanner.nextInt()
    val queue = LinkedList<Process>()
    (1..n).forEach {
        queue.add(Process(scanner.next(), scanner.nextInt()))
    }
    run(queue, q)

}
