P = Struct.new(:name, :time)
n, q = gets.split.map(&:to_i)
list = []
n.times{
	name, time = gets.split
	list.push P.new(name, time.to_i)
}
total = 0
while list.size > 0
	p = list[0]
	if q >= p.time
		total += p.time
		list.shift
		puts [p.name, total] * ' '
	else
		total += q
		p.time -= q
		list.rotate!
	end
end