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

n.times{
	name, time = gets.chomp.split
	queue << [name, time.to_i]
}

total = 0
until queue.empty?
	task = queue.shift
	if task[1] > q
		total += q
		queue.push [task[0], task[1] - q]
	else
		total += task[1]
		puts "#{task[0]} #{total}"
	end
end