n, q = gets.chomp.split(' ').map(&:to_i)
process = readlines.map do |line|
  name, time = line.chomp.split(' ')
  { name: name, time: time.to_i }
end

cnt_time = 0

while !process.empty?
  cur_process = process[0]
  if cur_process[:time] > q
    cnt_time += q
    last_process = { name: cur_process[:name], time: cur_process[:time] - q }
    process.shift
    process << last_process
  else
    cnt_time += cur_process[:time]
    process.shift
    puts "#{cur_process[:name]} #{cnt_time}"
  end
end

