i = []
c = 0

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

n.times do
  k, v = gets.split
  v = v.to_i
  c += v < q ? v : q
  v -= q
  v <= 0 ? (puts "#{k} #{c}") : i << [k, v]
end

until i.empty?
  k, v = i.shift
  c += v < q ? v : q
  v -= q
  v <= 0 ? (puts "#{k} #{c}") : i << [k, v]
end