var stdin = require('fs').readFileSync('/dev/stdin', 'utf8');
var lines = stdin.split('\n');
var header = lines.shift().trim().split(' ');
var n = parseInt(header[0], 10);
var q = parseInt(header[1], 10);
var tasks = [];
lines.forEach(function(line) {
  if (line !== '') {
    var task = line.trim().split(' ');
    tasks.push({
      name: task[0],
      time: parseInt(task[1], 10)
    });
  }
});
var time = 0;
while (tasks.length > 0) {
  var task = tasks.shift();
  if (task.time - q <= 0) {
    time += task.time;
    console.log([task.name, time].join(' '));
  } else {
    task.time -= q;
    tasks.push(task);
    time += q;
  }
}