const input = require('fs').readFileSync('/dev/stdin', 'utf8');

const list = input.trim().split('\n');
let [ n, q ] = list.shift().split(' ');

class Process {
  constructor(name, time) {
    this.name = name;
    this.time = time;
  }
}

const queue = [];
for (let i = 0; i < n; i++) {
  const [ name, time ] = list[i].split(' ');
  queue.push(new Process(name, time));
}

let totalTime = 0;
while (queue.length) {
  const p = queue.shift();
  const executeTime = Math.min(p.time, q);
  totalTime += executeTime;
  if (p.time > executeTime) {
    queue.push(p);
  } else {
    console.log(p.name + ' ' + totalTime);
  }
}

