
class MyQueue
  def initialize
      @stack1 = []
      @stack2 = []
  end
  def shift
    if @stack1.length == 0
      return @stack2.shift
    else
      return @stack1.shift
    end
  end

  def push push_value
    if @stack1.length == 0
      @stack2.each do |value|
        @stack1.push value
      end
      @stack1.push push_value
      @stack2.clear
    else
      @stack1.each do |value|
        @stack2.push value
      end
      @stack2.push push_value
      @stack1.clear
    end
  end

    def length
      if @stack1.length == 0 && @stack2.length == 0
        return 0
      end

      if @stack1.length == 0
        return @stack2.length
      else
        return @stack1.length
      end
    end

    def debug_list
      p @stack1
      p @stack2
    end
end


process_list = MyQueue.new
STDIN.each_line {|line|
  res = line.split " "
  process_list.push res
}

# process_list.debug_list
result_time = 0
a = process_list.shift
process_count = a[0].to_i
quantum_time = a[1].to_i
while process_list.length != 0
  process = process_list.shift
  consume_time = process[1].to_i
  if consume_time <= quantum_time
    result_time = result_time + consume_time
    print process[0], " ", result_time, "\n"
    next
  end

  result_time = result_time + quantum_time
  process[1] = (consume_time - quantum_time).to_s
  process_list.push process
end

