object Main extends App {
    val in = io.Source.stdin.getLines.map(_.split(" ")map(_.toInt))
    for (Array(n) <- in if n != 0) {
        val map = in.take(n.toInt).foldLeft(Map[Int, Long]())((acc, x) => x match {
            case Array(e, p, q) =>
                if (acc contains e) acc.updated(e, acc(e) + p.toLong * q)
                else acc + (e -> p.toLong * q)
        })
        val x = map.filter(_._2 >= 1000000).map(_._1)
        println(if (x.size == 0) "NA" else x.mkString("\n"))
    }
}