import std.stdio;
import std.array;
import std.conv;

void main(){
	int n, id, value, quantity;
	bool na;
	bool[int] listed;
	int[] printOrder;
	while (1) {
		readf("%d\n", &n);
		if(n == 0) break;
		na = true;
		for (int i = 0; i < n; i++) {
			readf("%d %d %d\n", &id, &value, &quantity);
			printOrder.insert(0, id);
			auto digit = to!string(value).length + to!string(quantity).length;
			if((digit >= 8 || value*quantity >= 1000000) &&  !(id in listed)){
				listed[id] = true;
				na = false;
			}
		}
		foreach (i; printOrder) {
			if(i in listed && listed[i]){
				writeln(i);
				listed[i] = false;
			}
		}
		if(na) writeln("NA");
	}
}