class P
  def initialize(str)
    tmp = str.split(" ")
    @name = tmp[0]
    @time = tmp[1].to_i
  end

  def decrease_time(value)
    @time -= value
  end

  attr_reader :name, :time
end

n, q = gets.split(" ").map(&:to_i)
ps = (1..n).map { P.new gets }
elapsed = 0
loop do
  p = ps.shift
  p.decrease_time(q)
  if p.time <= 0
    elapsed += q + p.time
    puts "#{p.name} #{elapsed}"
  else
    elapsed += q
    ps.push p
  end
  break if ps.size == 0
end