n, q = gets.split.map(&:to_i)
x = []
n.times do
  name, time = gets.chomp.split
  x << [name, time.to_i]
end
t = 0
while x.length > 0
  y = x.shift
  if y[1] <= q
    t += y[1]
    puts "#{y[0]} #{t}"
  else
    t += q
    y[1] -= q
    x << y
  end
end
