class Pro
  attr_accessor :name, :time
  def initialize(name, time)
    @name = name
    @time = time
  end
end

n, q = gets.split.map(&:to_i)
queue = []
n.times do
  p, t = gets.chomp.split
  pro = Pro.new(p, t.to_i)
  queue << pro
end
time = 0
while !queue.empty? do
  p = queue.shift
  t = [q, p.time].min
  time += t
  p.time -= t
  if p.time <= 0
    puts "#{p.name} #{time}"
  else
    queue << p
  end
end
