import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
//import std.regex;
import std.container;

void main()
{
	int n;

	while (n = readln.chomp.to!int, n) {
		int cnt;
		long[string] sell;
		string[] keys;
		bool[string] f;

		foreach (i; 0..n) {
			auto x = readln.split;
			auto w = x[1..$].map!(to!long);
			sell[x[0]] += w[0] * w[1];
			keys ~= x[0];
		}
		foreach (k; keys) {
			if (sell[k] >= 1_000_000 && f.get(k, 1)) {
				k.writeln;
				f[k] = 0;
				cnt++;
			}
		}
		if (!cnt) writeln("NA");
	}
}