line_count,limit_time=gets.split.map(&:to_i)
array=[]
line_count.times do |i|
  name,time=gets.split
  array.push [name,time.to_i]
end
total=0
while !array.empty?
  p,t=array.shift
  if t<=limit_time
    total+=t
    puts "#{p} #{total}"
  else
    t-=limit_time
    total+=limit_time
    array.push [p,t]
  end
end