n, q = gets.split.map(&:to_i)
queue = []
n.times do
  name, time = gets.split
  queue << { name: name, time: time.to_i}
end
current = 0
loop do
  break if queue.empty?

  data = queue.shift
  current += [q, data[:time]].min
  if data[:time] <= q
    puts data[:name] + ' ' + current.to_s
  else
    queue << { name: data[:name], time: data[:time] - q }
  end
end
