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.size != 0
  process,time=array.shift
  if time<=limit_time
    total+=time
    puts "#{process} #{total}"
  else
    time-=limit_time
    total+=limit_time
    array.push [process,time]
  end
end