
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int n = 0; // ???????????°
		int earningsValue = 0;
		int numberSales = 0;
		long totalSales = 0;
		int number;
		ArrayList<Integer> millionList = new ArrayList<Integer>(); // ????°?
															// 100????¶?????????????
		Scanner sc = new Scanner(System.in);
		// ???????????\???
		while (true) {
			Map<Integer, Long> map = new HashMap<>();
			n = sc.nextInt(); // ???????????°??\???
			if (n == 0) { // n?????\?????§0?????\??????????????¨??????
				break;
			}
			for (int i = 0; i < n; ++i) {
				number = sc.nextInt(); // ????????????
				if(1 >= number && number>= 4000){
					System.exit(0);
				}
				System.out.println("????????????:" + number);
				earningsValue = sc.nextInt(); // ?£????????????????
				System.out.println("?£??????????:" + earningsValue);
				numberSales = sc.nextInt(); // ?£??????°
				System.out.println("?£?????????°:" + numberSales);
				totalSales =(long)earningsValue * (long)numberSales; // ?£???????????????????£??????°
															// **????????????????????\???
				System.out.println("?£??????????:" + totalSales);
				if (map.containsKey(number)) { // ????????????????¢???? **true?????????
					totalSales += map.get(number); // ????????????????????£?????´????£???????????????´??°??????
					map.remove(number); //
				}
				map.put(number, totalSales); // ??????????????¨?£????????¨????????????????
			}
			// ????????¨?????????????´?
			Iterator entries = map.entrySet().iterator();
			int i = 0;
			while (entries.hasNext()) {
				Map.Entry entry = (Map.Entry) entries.next();
				int numberName = (int) entry.getKey();
				long sales = (long)entry.getValue();
				if (sales >= 1000000) {
					millionList.add(numberName);
					++i;
				}
				if(i == 0){
					millionList.add(-1); // 100????????????????????????????????°-1?????\??????(NA??¨)
					break;
				}
			}

			map.clear();
		}
		// ????????????
		for(int i = 0; i < millionList.size(); ++i){
			if(millionList.get(i) != 0 && millionList.get(i) != -1){
				System.out.println(millionList.get(i));
			}
			else if(millionList.get(i) == -1){
				System.out.println("NA");
			}
		}
		sc.close();
	}

}