n, q = gets.chomp.split(" ").map(&:to_i)
processes = []
n.times do |i|
  name, time = gets.chomp.split(" ")
  time = time.to_i
  processes << [name, time]
end
endtime = 0
until processes.empty?
  task = processes.shift
  if task[1] <= q then
    endtime += task[1]
    puts "#{task[0]} #{endtime}"
  else
    endtime += q
    task[1] -= q
    processes.push(task)
  end
end