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 tm = 0
    while (!queue.isEmpty) {
        val (n, t) = queue.dequeue
        if (t-q <= 0) {
            tm += t
            println(n + " " + tm)
        } else {
            tm += q
            queue.enqueue((n, t-q))
        }
    }
}