class MyProcess
  attr_reader :name
  def initialize(name, time)
    @name = name
    @time = time.to_i
  end

  def execute(time)
    @time -= time
    return time if @time >= 0

    @time + time
  end

  def finished?
    @time <= 0
  end
end

n, q = gets.split.map(&:to_i)
queue = n.times.map{ MyProcess.new(*gets.split) }

elapsed = 0
until queue.empty?
  process = queue.shift
  elapsed += process.execute(q)

  if process.finished?
    puts "#{process.name} #{elapsed}"
  else
    queue.push(process)
  end
end