import scala.io.StdIn.readLine;
import scala.reflect.ClassTag;
object Main {
    def main(args: Array[String]): Unit = {
        val line = readLine.split(" ").map(_.toInt);
        val n = line(0);
        val q = line(1);
        val que = new Queue[(String, Int)](n);
        for (i <- 0 until n) {
            val proc = readLine.split(" ");
            que.enqueue((proc(0), proc(1).toInt));
        }
        var total = 0;
        while (que.isEmpty == false) {
            val (name, time) = que.dequeue;
            if (time <= q) {
                total += time;
                println("%s %d".format(name, total));
            } else {
                total += q;
                que.enqueue((name, time - q));
            }
        }
    }
}
class Queue[A](size: Int)(implicit m: ClassTag[A]) {
    private val arr = m.newArray(size);
    private var leftPtr = 0;
    private var rightPtr = 0;
    private var cnt = 0;
    def isEmpty: Boolean = cnt == 0;
    def isFull: Boolean = cnt == size;
    def enqueue(e: A): Unit = if (isFull) {
        throw new RuntimeException("queue full")
    } else {
        arr(rightPtr) = e;
        cnt += 1;
        rightPtr = if (rightPtr + 1 == size) 0 else rightPtr + 1;
    }
    
    def dequeue: A = if (isEmpty) {
        throw new NoSuchElementException("queue empty");
    } else {
        val e = arr(leftPtr);
        cnt -= 1;
        leftPtr = if (leftPtr + 1 == size) 0 else leftPtr + 1;
        e;
    }
}
