i = $<.read

order, *works = i.split("\n").map do |e|
  a, b = e.split
  [a, b.to_i]
end

c = 0

until works.empty?
  k, v = works.shift
  c += v < order[1] ? v : order[1]
  v -= order[1]
  v <= 0 ? (puts "#{k} #{c}") : works << [k, v]
end