#ALDS_1_3_B Queue
input = IO
# input = DATA
procs = []
completed = []
qtime = 0
n,q = input.gets.chomp.split.map(&:to_i)
n.times do
  name,time = input.gets.split
  procs.push(Hash[name,time.to_i])
end

while(procs.any?) do
  prok = procs.shift
  v = prok.first[-1]
  if (v > q) then
    prok[prok.first[0]]= v - q
    procs.push(prok)
    # binding.pry
    qtime += q
  else
    qtime += v
    puts "#{prok.first[0]} #{qtime}"
  end
end
