line1 = STDIN.gets.chomp.split(" ")
n = line1[0].to_i
q = line1[1].to_i

queue = Array.new(n)
n.times do |i|
  line = STDIN.gets.chomp.split(" ")
  process = [line[0], line[1].to_i]
  queue[i] = process
end

time = 0
processes_ended = Array.new
while queue.empty? == false
  process = queue.shift
  if process[1] > q
    time += q
    process[1] -= q
    queue.push(process)
  else
    time += process[1]
    process[1] -= process[1]
    puts "#{process[0]} #{time}"
  end
end