class Task 
  def initialize(name, time)
    @name = name
    @time = time
  end
  attr_accessor :name, :time

  def process(quantum)
    if (@time > quantum) then
      @time -= quantum
      return quantum
    elsif
      a = @time
      @time = 0
      return a
    end
  end
end

n, q = gets.chomp.split(' ').map(&:to_i)
tasks = []
n.times do |i|
  array = gets.chomp.split(' ')
  tasks << Task.new(array[0], array[1].to_i)
end

proc_time_sum = 0
while (tasks.size > 0) do
  task = tasks.shift
  work_time = task.process(q)
  proc_time_sum += work_time

  if (task.time > 0) then
    tasks.push(task)
  else
    puts "#{task.name} #{proc_time_sum}"
  end
end