
import java.util.Queue
import java.util.LinkedList
class Job(val n:String,val c:Int)
{
    public var namae:String = n
    public var cost:Int = c
}
fun main(args: Array<String>) {
    //val n = readLine()!!.toInt()
    val input: List<String> = readLine()!!.split(" ").map { it.toString() }
    val q:Int =input[1].toInt()
    var t :Int=0
    val task: Queue<Job> = LinkedList<Job>()
    for (i in (1..input[0].toInt())) {
        val tmp = (readLine()!!.split(" ").map { it.toString() })
        task.add(Job(tmp[0], tmp[1].toInt()))
    }
    while (task.count()>0)
    {
        var i :Job = task.remove()
        if (i.cost>q)
        {
            t = t + q
            task.add(Job(i.namae,i.cost-q))
        }
        else
        {
            t = t + i.cost
            println(i.namae + " " + t)
        }
    }
}
