class Array
  alias_method :enq, :push
  alias_method :deq, :shift
end

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

queue = []
n,q = gets.chomp.split(" ").map{|x| x.to_i}
for i in 1..n do
  name,time = gets.chomp.split(" ")
  queue.enq(Pro.new(name,time.to_i))
end

t = 0
while queue.size > 0 do
  p = queue.deq
  if p.time > q
    t += q
    p.time -= q
    queue.enq(p)
  else
    t += p.time
    printf("%s %d\n",p.name,t)
  end
end
