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

queue = []
n.times do
	name, time = gets.split
	time = time.to_i
	queue.push({:name => name, :time => time})
end

jikoku = 0
while (que = queue.shift) != nil
	if que[:time] <= q
		jikoku += que[:time]
		printf("%s %d\n", que[:name], jikoku)
	else
		jikoku += q
		queue.push({:name => que[:name], :time => que[:time] - q})
	end
end