def main(input = STDIN)
  n, q = input.gets.split(" ").map(&:to_i)
  queue = Array.new(n)
  i = -1
  n.times do
    queue[i += 1] = Pro.new(*input.gets.split(" "))
  end
  i = 0
  last = 0
  now_time = 0
  size = n
  while size > 0
    now_time += q
    temp = queue[i].execute(q)
    if temp <= 0
      now_time += temp
      puts queue[i].name + " " + now_time.to_s
      size -= 1
      i = (i + 1) % n
    else
      queue[last] = queue[i]
      i, last = (i + 1) % n, (last + 1) % n
    end
  end
end
class Pro
  attr_reader :name
  def initialize(name, time)
    @name, @time = name.to_s, time.to_i
  end
  def execute(quantum)
    return @time -= quantum
  end
end
main