var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var obj={};
var abc=[];
for(var i=0;i<Arr.length;i++){
var arr=Arr[i].split(" ").map(Number);
   if(i!=0 && arr.length==1){
      var cnt=0;
      for(var j=0;j<abc.length;j++){
         if(obj[abc[j]]>=1000000){console.log(abc[j]);cnt++;}
      }
      if(cnt==0)console.log("NA");
      if(arr[0]==0)break;
      obj={};
      abc=[];
   }else if(arr.length==3){
       if(!obj.hasOwnProperty(arr[0])){obj[arr[0]]=arr[1]*arr[2];abc.push(arr[0]);}
       else obj[arr[0]]+=arr[1]*arr[2];
   }
}