process.stdin.resume();
process.stdin.setEncoding("utf8");

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

const lines = [];

reader.on("line", (line) => {
  lines.push(line);
});

reader.on("close", () => {
  const [n, q] = lines[0].split(" ").map(Number);
  const processes = [];
  for (let i = 1; i <= n; i++) {
    const [name, time] = lines[i].split(" ");
    processes.push([name, time - 0]);
  }

  let processedTime = 0;
  while (processes.length > 0) {
    const [name, time] = processes.shift();
    const processingTime = Math.min(time, q);
    processedTime += processingTime;
    const nextTime = time - processingTime;
    if (nextTime > 0) {
      processes.push([name, nextTime]);
    } else {
      console.log(`${name} ${processedTime}`);
    }
  }
});

