x = gets.split(" ").map{|k|k.to_i}

n = x[0]
q = x[1]
time = 0
hash = Hash.new
ans_hash = Hash.new

n.times do
    y = gets.split(" ")
    hash[y[0]] = y[1].to_i
end

until ans_hash.length == n
    key,value = hash.shift
    if value <= q
        time += value
        ans_hash[key] = time
    else
        time += q
        value -= q
        hash[key] = value
    end
end

ans_hash.each do |k,v|
    puts "#{k} #{v}"
end
