
class Array
  alias_method :enqueue, :push
  alias_method :dequeue, :shift

  def exists?
    !self.empty?
  end
end

n, q = gets.chomp.split(" ").map(&:to_i)
queue = []

n.times {
  a, b = gets.chomp.split(" ")
  queue.enqueue([a, b.to_i])
}

elaps = 0

while queue.exists?
  key, value = queue.dequeue
  min = [value, q].min
  temp_time = value - min
  elaps += min
  if temp_time > 0
    queue.enqueue([key, temp_time])
  else
    puts "#{key} #{elaps}"
  end
end