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

que = []
while str = gets
  name, time = str.chomp.split
  time = time.to_i
  que.push name: name, time: time
end

past_time = 0
while !que.empty?
  process = que.shift

  if process[:time] <= q
    past_time += process[:time]
    puts "#{process[:name]} #{past_time}"
  else
    past_time += q
    process[:time] -= q
    que.push process
  end
end