while n = gets.to_i
	break if n.zero?

	dataset = Hash.new
	dataset.default = 0
	
	n.times do
		id, selling_price, quantity = gets.chomp.split.map(&:to_i)
		dataset[id] += selling_price * quantity
	end
	
	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