class TaskQ
  def initialize(qtime)
    @queue=[]
    @qtime=qtime
    @etime=0
  end

  def enq(name, qtime)
    @queue<<Process.new(name,qtime)
  end

  def deq
    process=@queue.shift
    process.ptime-=@qtime
    @etime+=@qtime
    if process.ptime<=0
      @etime+=process.ptime
      puts "#{process.name} #{@etime}"
    else
      @queue<<process
    end
  end

  def empty?
    return @queue.empty?
  end

  class Process
    attr_accessor :name, :ptime
    def initialize(name, ptime)
      @name=name
      @ptime=ptime
    end
  end
end

n,q=gets.split.map &:to_i
task=TaskQ.new(q)
n.times do
  name,ptime=gets.split
  task.enq(name,ptime.to_i)
end

loop do
  break if task.empty?
  task.deq
end