N, q = gets.chomp.split.map(&:to_i)
tasks = Array.new
queue = Array.new
elaps = 0
N.times { tasks.push(gets.chomp.split) }
class Task
  attr_accessor :name, :time

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

tasks.each do |a, b|
  queue.push(Task.new(a, b))
end

until queue.empty?
  u = queue.shift
  c = [q, u.time].min
  u.time -= c
  elaps += c
  if u.time > 0
    queue.push(u)
  else
    print "#{u.name} #{elaps}\n"
  end
end

