I[4000],S[4000],p[4000],N;i,u,c;main(n){for(;scanf("%d",&n),n;memset(p,N=0,16000)){for(;n--;p[i-1]?S[p[i-1]-1]+=u*c:(I[N]=i,S[N]=u*c,p[i-1]=++N))scanf("%d%d%d",&i,&u,&c);c=0;for(n=-1;++n<N;)S[n]<1e6||printf("%d\n",c=I[n]);c||puts("NA");}exit(0);}