class EmployeeRecord
  NUM_EMPLOYEE = 4000
  MILLION = 1000000
  
  def initialize
    @sales = Array.new(NUM_EMPLOYEE + 1).fill(0, 0...(NUM_EMPLOYEE+1))
  end
  
  def updateSales(id, newSales)
    @sales[id] += newSales
  end
  
  def printIdOverMillionSales(inputId)
    count = 0
    for i in 0...inputId.size
      if @sales[inputId[i]] >= MILLION
        count += 1
        puts inputId[i]
      end
    end
    puts "NA"   if count == 0
  end
end


employee = nil
while true
  n = gets.to_i
  a = Array.new
  break   if n == 0
  employee = EmployeeRecord.new
  for i in 0...n
    input = gets.split(" ")
    id = input[0].to_i
    a << id
    price = input[1].to_i
    numItems = input[2].to_i
    employee.updateSales(id, price * numItems)
  end
  employee.printIdOverMillionSales(a)
end