n, q = gets.split.map(&:to_i)
processes = []
total_time = 0

n.times do
  processes.push(gets.split)
end

while !processes.empty? do
  process = processes.shift

  name = process[0]
  time = process[1].to_i

  if time <= q
    total_time += time
    puts "#{name} #{total_time}"
  else
    total_time += q
    processes.push([name, time - q])
  end
end

