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

var name_start = 2;
var name_end = 2 + 2 * n;
var rest_start = 3;
var rest_end = 3 + 2 * n;

for (i = rest_start; i < rest_end; i += 2) line[i] = Number(line[i]);

// run all processes once
for (i = name_start; i < name_end; i += 2) {
    if (line[i+1] <= q) {
        time += line[i+1];
        console.log(line[i], time);
    } else {
        time += q;
        line[i+1] -= q;
        queue.push(i);
    }
}

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