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

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

const solve = (arr, q) => {
    const result = [];
    let time = 0;
    for (;arr.length !== 0;) {
        const currentQ = arr.shift();
        if (currentQ[1] - q <= 0) {
            const endQ = [currentQ[0], currentQ[1] + time];
            result.push(endQ);
            time += currentQ[1];
        } else {
            const newQ = [currentQ[0], currentQ[1] - q];
            arr.push(newQ);
            time += q;
        }
    } 

    return result;
};

const q = parseInt(line[0].split(' ')[1]);
const data = line.slice(1, line.length-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);

