var line = require('fs').readFileSync('/dev/stdin', 'utf8').split(/ |\n/);
var n = Number(line[0]);
var q = Number(line[1]);

var name = new Array(n);
var rest = new Int32Array(n);
var next = new Int32Array(n);

(function init() {
    var i, j = 2;
    for (i = 0; i < n; i++) {
        name[i] = line[j++];
        rest[i] = Number(line[j++]);
        next[i] = i + 1;
    }
})();

(function simulate() {
    var time = 0, idx, end = false, delta;
    while (!end) {
        end = true;
        for (idx = 0; idx < n; idx = next[idx]) {
            if (rest[idx] == 0) continue;
            end = false;
            delta = (rest[idx] < q) ? rest[idx] : q;
            rest[idx] -= delta;
            time += delta;
            if (rest[idx] == 0) {
                console.log(name[idx], time);
                if (idx != 0 && idx != n - 1) {
                    next[idx - 1] = next[idx];
                }
            }
        }
    }
})();