let lines = require("fs").readFileSync("/dev/stdin","utf-8").trim().split("\n");
const args = lines.shift().split(" ").map(Number);
const n = args[0];
const q = args[1];
let processes = [];
for(let line of lines){
    let process = line.split(" ");
    process[1] = parseInt(process[1]);
    processes.push(process);
}
let time = 0;
while(processes.length!==0){
    let process = processes.shift();
    process[1] -= q;
    if(process[1]<=0){
        time+=q+process[1];
        console.log(process[0]+" "+time);
    }else{
        time+=q;
        processes.push(process);
    }
}
