class Process1
  @name
  @time
  @endtime

  attr_accessor :name, :time, :endtime

  def initialize(name, time)
    @name = name
    @time = time
  end
end

def main
  line1 = STDIN.gets.chomp.split(" ")
  n = line1[0].to_i
  q = line1[1].to_i

  queue = Array.new(n)
  n.times do |i|
    line = STDIN.gets.chomp.split(" ")
    process = Process1.new(line[0], line[1].to_i)
    queue[i] = process
  end

  time = 0
  processes_ended = Array.new
  while queue.empty? == false
    process = queue.shift
    if process.time > q
      time += q
      process.time -= q
      queue.push(process)
    else
      time += process.time
      process.time -= process.time
      process.endtime = time
      processes_ended.push(process)
    end
  end
  processes_ended.each do |process|
    puts "#{process.name} #{process.endtime}"
  end
end

main