n, q = gets.split.map(&:to_i)
list = []
time = 0

n.times do |i|
	name, quantum = gets.chomp.split
	list << [name, quantum.to_i]
end

loop do
	head = list.shift
	exit if head == nil
	
	time += head[1] < q ? head[1] : q
	remain = head[1] - q
	
	if remain > 0
		list.push([head[0], remain])
	else
		puts "#{head[0]} #{time}"
	end
end

