class RingBuffer
  def initialize(cap)
    @cap = cap + 1
    @values = Array.new(@cap)
    @head = @tail = 0
  end

  def empty?
    @head == @tail
  end

  def full?
    @head == ((@tail + 1) % @cap)
  end

  def enq(value)
    raise 'buffer is full' if full?

    @values[@tail] = value
    @tail = (@tail + 1) % @cap
    nil
  end

  def deq
    raise 'buffer is empty' if empty?

    value = @values[@head]
    @head = (@head + 1) % @cap
    value
  end
end

n, q = gets.split.map(&:to_i)

buffer = RingBuffer.new(n)

while line = gets
  name, time = line.split
  buffer.enq(name: name, time: time.to_i)
end

current_time = 0

until buffer.empty?
  process = buffer.deq

  elapsed_time = [process[:time], q].min
  process[:time] -= elapsed_time
  current_time += elapsed_time

  if process[:time] > 0
    buffer.enq(process)
  else
    puts "#{process[:name]} #{current_time}"
  end
end