var input = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n').map(function (value) {
  return value.split(' ');
});

var tmp = input.shift();
var n = parseInt(tmp[0]);
var quantum = parseInt(tmp[1]);

var time = 0;
var currentProcess = null;
var left = 0;

while (input.length > 0) {
  var current = input.shift();
  left += quantum;
  currentQ = parseInt(current[1]);
  if (currentQ > left) {
    current = [current[0], currentQ - left];
    time += left;
    input.push(current);
  } else {
    time += currentQ;
    console.log([current[0], time].join(' '));
  }
  left = 0;
}