class Job
  attr_reader :name
  attr_accessor :remaining_time, :finished_at

  def initialize(name, remaining_time)
    @name = name
    @remaining_time = remaining_time
    @finished_at = nil
  end
end

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

unfinished_jobs = $stdin.readlines.map do |line|
  name, remaining_time = line.split

  Job.new(name, remaining_time.to_i)
end

finished_jobs = []

current_time = 0

until unfinished_jobs.empty?
  job = unfinished_jobs.shift

  elapsed_time = [job.remaining_time, q].min
  job.remaining_time -= elapsed_time
  current_time += elapsed_time

  if job.remaining_time > 0
    unfinished_jobs << job
  else
    job.finished_at = current_time
    finished_jobs << job
  end
end

puts finished_jobs.map {|job| "#{job.name} #{job.finished_at}" }