class Pro
  attr_reader :name, :time
  def initialize(name, time)
    @name = name
    @time = time
  end
end

n, q = gets.split.map(&:to_i)
processes = $stdin.read.split()
queue = []
for i in 0..n-1
  queue[i] = Pro.new(processes[2*i], processes[2*i+1].to_i)
end

total_time = 0
while queue.size > 0 do
  que = queue.shift
  if que.time - q > 0 then
    queue.push(Pro.new(que.name, que.time - q))
    total_time += q
  else
    total_time += que.time
    printf "%s %d\n",que.name, total_time
  end
end