n, q = gets.split.map(&:to_i)
queue = []
n.times do
  name, rest = gets.chomp.split
  queue << [name, rest.to_i]
end
time = 0
until queue.empty?
  name, rest = queue.shift
  if rest <= q
    time += rest
    puts "#{name} #{time}"
  else
    time += q
    queue << [name, rest - q]
  end
end
