Enumerator.new {|y|
  until (n = gets.to_i).zero?
    y << n.times.map { gets.split(" ").map(&:to_i) }
  end
}
  .flat_map {|params|
    targets = params
      .each_with_object({}) {|(id, n, p), acc| acc[id] = (acc[id] || 0) + n * p }
      .select {|id, tp| tp >= 1000000 }
      .keys
    targets.empty? ? ['NA'] : targets
  }
  .each(&method(:puts))