n, q = gets.chomp.split(' ').map(&:to_i)
ps = readlines.map(&:chomp).map{|l| a = l.split(' '); a[1] = a[1].to_i; a}

t = 0
while ps.length > 0
  p = ps.shift
  if p[1] <= q
    t += p[1]
    puts "#{p[0]} #{t}"
  else
    t += q
    p[1] -= q
    ps.push(p)
  end
end
