n, q = gets.split.map(&:to_i)
Job = Struct.new 'Job', :name, :time
jobs = n.times.map do
  name, time = gets.chomp.split
  Job.new(name, time.to_i)
end
t = 0
while jobs.size > 0
  j = jobs.shift
  if j.time > q
    t += q
    jobs << Job.new(j.name, j.time - q)
  else
    t += j.time
    puts "#{j.name} #{t}"
  end
end

