import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    for(int n; 0<(n=readln().chomp().to!int()); )
    {
        auto a = iota(n).map!(_=>readln().split().array()).array();
        long[string] t;
        foreach(v;a)
        {
            immutable s = v[1..$].map!(to!long).reduce!"a*b"();
            if(v[0] in t) t[v[0]] += s;
            else t[v[0]] = s;
        }
        bool[string] u;
        string[] ids;
        foreach(v;a)
            if(t[v[0]]>=1000000 && v[0] !in u) ids~=v[0], u[v[0]]=true;
        if(ids.length==0) writeln("NA");
        else foreach(id;ids) writeln(id);
    }
}