function main(stdin) {
    const _inputs = stdin.split("\n");
    let inputs = _inputs.map(ele => ele.split(' '));
    let [length, quantum] = inputs.shift();
    quantum = parseInt(quantum, 10);
    inputs = inputs.map(ele => [ele[0], parseInt(ele[1], 10)]);
    inputs = inputs.filter((e, i) => i < length);

    // 配列の要素の配列は参照
    executeQueue(quantum, inputs, length, 0);
}

function executeQueue(quantum, inputs, length, total){
    if(inputs.length) {
        const process = inputs[0];
        const cost = process[1];
        process[1] -= quantum;
        if (process[1] <= 0) {
            total += cost;
            console.log(`${process[0]} ${total}`);
            inputs.shift();
        } else {
            total += quantum;
            inputs.shift();
            inputs.push(process);
        }
        executeQueue(quantum, inputs, length, total);
    }
}


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

