while gets
	n = $_.to_i
	break if n.zero?
	dataset = Hash.new
	n.times do
		id, selling_price, quantity = gets.chomp.split.map(&:to_i)
		if dataset.has_key?(id)
			dataset[id] += selling_price * quantity
		else
			dataset[id] = selling_price * quantity
		end
	end
	p dataset
	satisfying_id = Array.new
	dataset.each_pair do |id, sales|
		satisfying_id << id if 1000000 <= sales
	end
	puts (satisfying_id.empty? ? "NA" : satisfying_id.sort)
end