def solve(quota, items)
  time = 0
  until items.empty?
    item = items.shift
    if item[:val] > quota
      item[:val] -= quota
      items.push(item)
      time += quota
    else
      time += item[:val]
      puts "#{item[:name]} #{time}"
    end
  end
end
size, quota = gets.split(" ").map(&:to_i)
items = Array.new(size) { name, val = gets.split(" "); {name: name, val: val.to_i}}
solve(quota, items)

