def alds13b
    n,q = gets.chomp.split(/\s/).map{|x| x.to_i}

    nt = []
    for i in 1..n
        na, ti = gets.chomp.split(/\s/)#.map{|x| x.to_i})
        nt.push([na, ti.to_i])
    end

    to = 0
    until nt == nil
        j = nt.delete_at(0)
        t = j[1] - q
        if t <= 0
            to += j[1]
            print "#{j[0]} #{to}\n"
            nt = nil if nt.length == 0
        else
            to += q
            j[1] -= q
            nt.push(j)
        end
    end
end

alds13b
