while (n=gets.to_i)!=0
  emp,ans=Array.new(4001,0),[]
  n.times do
    id,val,amo=gets.split.map(&:to_i)
    emp[id]+=val*amo
  end
  emp.each_with_index do |sum,idx|
    ans<<idx if sum>=1_000_000
  end
  puts ans.empty? ? "NA" : ans
end