class RoundRobbinQueue
  @quantum = 100
  @processes = [] #[[name, time]]
  @completed_processes = [] #[[name, elapsed]]
  @elapsed = 0

  def initialize(quantum, processes)
    @quantum = quantum
    @processes = processes
    @elapsed = 0
    @completed_processes = []
  end

  def execute_process
    length = @processes.length
    until @processes == []
      length = @processes.length
        if @processes[0][1] <= @quantum
          @elapsed += @processes[0][1]
          @completed_processes.push([@processes[0][0], @elapsed])
          @processes.delete_at(0)
        else
          @processes[0][1] -= @quantum
          @processes.push(@processes[0])
          @processes.delete_at(0)
          @elapsed += @quantum
        end
      end
      return @completed_processes
  end
end

input_values_nq = gets.chomp.split.map(&:to_i)
n = input_values_nq[0]
q = input_values_nq[1]
input_processes = []
n.times do
  input_value = gets.chomp.split
  input_value[1] = input_value[1].to_i
  input_processes.push([input_value[0], input_value[1]])
end
roundrobbinqueue = RoundRobbinQueue.new(q, input_processes)
output = roundrobbinqueue.execute_process
length = output.length
for i in 0..(length-1)
  print output[i][0]
  print " "
  print output[i][1]
  print "\n"
end