n, q = gets.split.map(&:to_i)

processes = n.times.map{|e|
  name, time = gets.split
  [name, time.to_i]
}

processed = []

t = 0
until processes.empty?
  top = processes.shift

  name, time = top
  rest = time - q

  if rest > 0
    processes << [name, rest]
    t += q
  else
    processed << [name, t + time]
    t += time
  end
end

processed.each do |name, t|
  puts "#{name} #{t}"
end

