'use strict';

const main = input => {
  const arr = input.split('\n');
  const n = Number(arr[0].split(' ')[0]);
  const q = Number(arr[0].split(' ')[1]);
  arr.shift();

  initialize();
  for (let i = 0; i < n; ++i) {
    enqueue({
      name: arr[i].split(' ')[0],
      t: Number(arr[i].split(' ')[1]),
    });
  }
  let elaps = 0;
  while (!isEmpty()) {
    const p = dequeue();
    if (p.t > q) {
      p.t -= q;
      enqueue(p);
      elaps += q;
    } else {
      elaps += p.t;
      console.log(p.name, elaps);
    }
  }
};

const MAX = 100000;
let head = 0;
let tail = 0;
let Q = [];

function initialize() {
  head = 0;
  tail = 0;
  Q = [];
}

function isEmpty() {
  return head === tail;
}

function isFull() {
  return head === (tail + 1) % MAX;
}

function enqueue(x) {
  if (isFull()) {
    // Error
    console.log('isFull');
    return;
  }
  Q[tail] = x;
  tail = (tail + 1) % MAX;
}

function dequeue() {
  if (isEmpty()) {
    // Error
    console.log('isEmpty');
    return;
  }
  const x = Q[head];
  head = (head + 1) % MAX;
  return x;
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

