loop do
   break if (n = gets.to_i) == 0
   db = []
   n.times do
      id,p,q = gets.split(" ").map{|x| x.to_i}
      info = db.assoc id
      if info == nil # add new
         db.push [id,p * q]
      else
         info[1] += p * q
      end
   end
   million_over = []
   db.each do |id,sale|
      million_over.push id if sale >= 1_000_000
   end
   if million_over.empty? # no match
      puts "NA"
   else
      million_over.each do |id|
         puts id
      end
   end
end