import java.io.BufferedReader
import java.io.InputStreamReader
import java.util.ArrayDeque


data class Job(val name: String, val time: Int)

fun main(args: Array<String>) {
    val expr = BufferedReader(InputStreamReader(System.`in`))
            .readText()
            .trim()
            .split(regex = """\s+""".toRegex())

    val timeSliceLength = expr[1].toInt()
    val jobsQueue = ArrayDeque<Job>()

    for (i in 2 until expr.size step 2) {
        jobsQueue.addLast(Job(name = expr[i], time = expr[i+1].toInt()))
    }

    var currentTime = 0

    while (jobsQueue.isNotEmpty()) {
        val thisJob = jobsQueue.removeFirst()
        if (thisJob.time > timeSliceLength) {
            jobsQueue.addLast(thisJob.copy(time = thisJob.time - timeSliceLength))
            currentTime += timeSliceLength
        } else {
            currentTime += thisJob.time
            println(thisJob.name + " " + currentTime)
        }
    }
}
