class EmployeesManager
    @employees = Array.new
    def self.add_sales_employee(id, price, amount)
        employee = @employees.find{|employee| employee.id == id}
        if employee.nil? then
            employee = Employee.new(id)
            @employees.push(employee)
        end
        employee.add_sales(price, amount)
    end
    def self.achieved_employees(quota)
        achieved_employees = Array.new
        @employees.each do |employee|
            achieved_employees.push(employee) if employee.get_sales >= quota
        end
        achieved_employees
    end
    def self.reset
        @employees.clear
    end
end

class Employee
    attr_accessor :id
    @sales
    def initialize(id)
        self.id = id
        @sales = 0
    end
    def add_sales(price, amount)
        @sales += amount * price
    end
    def get_sales
        @sales
    end
end

def settlement
    quota = 1000000
    achieved_employees = EmployeesManager.achieved_employees(quota)
    unless achieved_employees.empty?
        achieved_employees.each do |employee|
            puts employee.id
        end
    else
        puts "NA"
    end
    EmployeesManager.reset
end

while true
    n = gets.chop
    if n == '0' then
        break
    end
    n.to_i.times do
        id, price, amount = gets.split(" ").map(&:to_i)
        EmployeesManager.add_sales_employee(id, price, amount)
    end
    settlement
end

