nq, *process = readlines.map(&:chomp).map {|l| l.split}
n, q = nq.map(&:to_i)
process = process.map {|p| {name: p.first, time: p.last.to_i}}

finished = []
time = 0
while(true)
  head = process.shift
  if head[:time] > q
    head[:time] -= q
    time += q
    process << head
  else
    time += head[:time]
    finished << {name: head[:name], time: time }
  end
  break if process.empty?
end

finished.each do |v|
  puts "#{v[:name]} #{v[:time]}"
end
