p_num, quantum = gets.split.map {|x| x.to_i }
process = Array.new
p_num.times do
  key, time = gets.split
  process << [key, time.to_i]
end

now = 0
while !process.empty? do
  buf = process.shift
  if buf[1] <= quantum then
    now += buf[1]
    puts "#{buf[0]} #{now}"
  else
    now += quantum
    buf[1] -= quantum
    process.push buf
  end
end