object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ")).map(a => (a(0), a(1).toInt))
    val (_, q) = in.next
    val queue = scala.collection.mutable.Queue[(String, Int)]()
    in.foreach(queue.enqueue(_))
    var t = 0
    while (!queue.isEmpty) {
        if (queue.head._2 > 0) {
            val h = queue.dequeue
            if (h._2-q <= 0) {
                t += h._2
                println(h._1 + " " + t)
            } else {
                t += q
                queue.enqueue((h._1, h._2-q))
            }
        }
    }
}