function main() {
  var
  nq = input[0].split(' ').map(Number),
  n = nq[0], q = nq[1],
  queue = [], process,
  total;
  input.slice(1, 1+n).forEach(function (process) {
    process = process.split(' ');
    process[1] = Number(process[1]);
    queue.push(process);
  });

  total = 0;
  while(queue.length !== 0) {
    process = queue.shift();
    if (process[1] > q) {
      process[1] -= q;
      total += q;
      queue.push(process);
    } else {
      total += process[1];
      console.log(process[0] + ' ' + total);
    }
  }
}

var
input = '';

process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  input = input.split('\n');
  main();
});