n, q = gets.chomp.split(" ").map{|i|i.to_i}
queue = Array.new(2*n)
queue[0] = 0
1.upto(n) do |i|
  queue[i] = gets.chomp
end

tail = n
cnt = 0
queue.each do |p|
  next if p == 0
  break if p == nil
  p_n, p_t = p.split(" ")
  r = p_t.to_i - q
  if r <= 0
    cnt += p_t.to_i
    puts "#{p_n} #{cnt}"
  else
    cnt += q
    queue[tail+1] = "#{p_n} #{r}"
    tail += 1
  end
end
