input = gets.strip.split(" ")

n,q,s = input[0].to_i,input[1].to_i,0
process = Hash.new

n.times do
  input = gets.strip.split(" ")
  name,time = input[0],input[1].to_i
  process[name] = time
end

list = process.dup

while list.empty? == false
  tmp = list.first
  if (tmp[1] - q) > 0
    list.delete(tmp[0])
    list[tmp[0]] = tmp[1] - q
    s += q
  else
    list.delete(tmp[0])
    s += tmp[1]
    name,time = tmp[0],s
    puts "#{name} #{time}"
  end
end