import scala.io.StdIn._

object Main {
  def main(args: Array[String]): Unit = {
    var loop =true

    while (loop) {
      val n = readLine.toInt
      if (n == 0) loop = false
      else {
        var map = scala.collection.mutable.Map[Int, Int]()

        for (i <- 0 until n) {
          val s = readLine.split(' ').map(x => x.toInt)
          val emp = s(0)
          val price = s(1)
          val num = s(2)
          map += emp -> (map.getOrElse(emp, 0) + price * num)
        }

        val emps = map.filter(t => t._2 >= 1000000).keys
        if (emps.isEmpty) println("NA")
        else emps.foreach(println)
      }
    }
  }
}