object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ")).map(a => (a(0), a(1).toInt))
    val (_, q) = in.next
    val (names, times) = in.toArray.unzip
    var t = 0
    while (times.exists(_ > 0)) {
        times.indices.foreach{i =>
            if (times(i) >= 0) {
                if (times(i)-q < 0) {
                    t += times(i)
                    println(names(i) + " " + t)
                } else {
                    t += q
                }
                times(i) -= q
            }
        }
    }
}