n, q = gets.chomp.split.map(&:to_i)
queue = []
n.times do
    tmpArr = gets.chomp.split
    tmpArr[1] = tmpArr[1].to_i
    queue.push(tmpArr)
end

ans = []
t = 0
until queue.empty? do
    work = queue.shift
    if work[1] <= q then
        work[1] +=  t
        ans.push(work)
        t += work[1] - t
    else
        work[1] -= q
        queue.push(work)
        t += q
    end
end

ans.each { |e| puts e.join(' ') }
