n, q = gets.split.map(&:to_i)
process = []
n.times do
  p, t = gets.split
  t = t.to_i
  process << [p, t]
end

total = 0
while process.any?
  p, t = process.shift
  if t <= q
    total += t
    puts "#{p} #{total}"
  else
    t -= q
    total += q
    process << [p, t]
  end
end