row = gets.split
num, per_ms = [row[0].to_i, row[1].to_i]


queue = [];
(0..num - 1).each{
    name, ms = gets.split
    queue.push([name, ms.to_i])
}

time = 0
results = []
while queue.size > 0 do
    name, ms = queue.shift

    if ms > per_ms then
        time += per_ms
        queue.push([name, ms - per_ms])
    else
        time += ms
        results.push([name, time])
    end
end

results.each do |rl|
    puts "#{rl[0]} #{rl[1]}"
end
