var line = require('fs').readFileSync('/dev/stdin', 'utf8').split(/\n/);
var [n, q] = line.shift().split(/ /).map(Number);
var queue = line;
var i;
var time = 0;
var elem;
for (i in queue) {
    queue[i] = queue[i].split(/ /);
    queue[i][1] = Number(queue[i][1]);
}

// run processes on queue
while (queue.length != 0) {
    elem = queue.shift();
    if (elem[1] <= q) {
        time += elem[1];
        console.log(elem[0], time);
    } else {
        time += q;
        elem[1] -= q;
        queue.push(elem);
    }
}