timequeue = Array.new
namequeue = Array.new  
N,Q = gets.split.map(&:to_i)
proc =0.to_i
N.times do
name, time = gets.split
timequeue.push(time.to_i)
namequeue.push(name.to_s)
end

while !namequeue.empty? 
	data = timequeue.shift
	name = namequeue.shift
	if data> Q
		proc += Q
		data-=Q
		timequeue.push(data)
		namequeue.push(name)
	else
		proc += data
		print(name+" ")
		puts proc
	end

end