function main(_stdin) {
    const stdin = _stdin.split('\n');
    const [length, quantam] = stdin.shift().split(' ');
    const result = [];
    let cost = 0;

    const tasks = stdin.filter(e => e.length).map(e => e.split(' '));

    for(const task of tasks){
        const temp = Number(task[1]) - Number(quantam);
        if(temp > 0) {
            task[1] = temp;
            cost += Number(quantam);
            tasks.push(task);
        } else {
            cost += Number(task[1]);
            result.push(`${task[0]} ${cost}`);
        }
    }

    console.log(result.join('\n'));
}



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

