const config = {
    input: '/dev/stdin',
    newline: '\n'
};

const line = require('fs').readFileSync(config.input, 'utf-8').split(config.newline);

const solve = (arr, q, t) => {
    if (arr.length === 0) return [];
    const hd = arr[0];
    const tl = arr.slice(1);

    if (hd[1] - q <= 0) {
        const endQueue = [hd[0], t + hd[1]];
        return [endQueue, ...solve(tl, q, t + hd[1])];
    } else {
        const newQueue = [hd[0], hd[1] - q];
        return solve([...tl, newQueue], q, t + q);
    }
};

const q = parseInt(line[0].split(' ')[1]);
const data = line.slice(1).map(x => x.split(' ')).map(x => [x[0], parseInt(x[1])]);
const ans = solve(data, q, 0).map(x => x[0] + ' ' + x[1]).join('\n');

console.log(ans);

