n_process, quantum = gets.chomp.split.map(&:to_i)
queue = []
n_process.times{
    name, sec = gets.chomp.split
    queue.push [name, sec.to_i]
}

time = 0
until queue.empty?
    process = queue.shift
    # p process
    if process[1] <= quantum
        # p "?¶???????"
        time += process[1]
        puts "#{process[0]} #{time}"
    else
        # p "?¶??????????"
        time += quantum
        queue.push [process[0], process[1] - quantum]
        # p "?????¨#{process[1] - quantum}"
    end
end