def input_data_sets
  data_sets = []
  
  while data_count = gets.strip.to_i
    return data_sets if data_count.nil? || data_count.to_i == 0
    data_sets << input_data_set(data_count)
  end
  
  data_sets
end

def input_data_set(data_count)
  data_count.times.map{ gets.strip.split }
end

class Employee
  RENDERABLE_THRESHOLD = 1_000_000
  
  attr_reader :id
  
  def initialize(__id)
    @id = __id
    @sales = 0
  end
  
  def add_sales(unit_value, count)
    @sales += unit_value.to_i * count.to_i
  end
  
  def renderable?
    @sales >= RENDERABLE_THRESHOLD
  end
  
  def to_s
    id.to_s
  end
end

class EmployeesContainer
  def initialize(date_set)
    @employees = []
    date_set.each do |data|
      get_employee(data[0]).add_sales(*data[1, 2])
    end
  end
  
  def get_employee(id)
    @employees.find{ |e| e.id == id } || add_employee(id)
  end
  
  def add_employee(id)
    employee = Employee.new(id)
    @employees << employee
    employee
  end
  
  def add_sales(id, unit_value, count)
    get_employee(id).add_sales(unit_value, count)
  end
  
  def render_to_string
    renderable_employees = @employees.select(&:renderable?)
    if renderable_employees.empty?
      "NA"
    else
      renderable_employees.map(&:to_s).join("\n")
    end
  end
end

data_sets = input_data_sets
=begin
data_sets = [
  #4
  [
    %w(1001 2000 520),
    %w(1002 1800 450),
    %w(1003 1600 625),
    %w(1001 200 1220)
  ],
  #2
  [
    %w(1001 100 3),
    %w(1005 1000 100),
  ],
  #2
  [
    %w(2013 5000 100),
    %w(2013 5000 100),
  ],
  #0
]
=end

data_sets.each do |data_set|
  puts EmployeesContainer.new(data_set).render_to_string
end