import scala.collection.mutable.Queue
import io.Source.stdin

object Main extends App {
    val queue = Queue[(String, Int)]()
    stdin.getLines.foreach(a => {
        val b = a.split(" ")
        queue.enqueue((b(0), b(1).toInt))
    })

    val (_, q) = queue.dequeue
    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))
        }
    }
}