let inputString = '';

process.stdin.on('data', (input) => {
  inputString += input;
});

process.stdin.on('end', () => {
  const input = inputString
    .replace(/\s*$/, '')
    .split('\n')
    .map(str => str.replace(/\s*$/, ''))
    .map(str => str.split(' '))
    .map(arr => [arr[0], Number(arr[1])]);
    
  roundRobin(input);
});

const roundRobin = (arr) => {
  let total = 0;
  const [n, q] = arr.shift();
  while (arr.length > 0) {
    const [name, time] = arr.shift();
    const rest = time - q;
    total += q;

    if (rest > 0) {
      arr.push([name, rest]);
    } else {
      total += rest;
      console.log(`${name} ${total}`);
    }
  }
};
