while n = gets.chomp.to_i
  break if n == 0
      tmp = Hash.new(0)
      tmp2 = Hash.new(false)
  n.times do |i|
    line = gets
    e,p,q = line.split.map(&:to_i)
    tmp[e] += p * q
    if p * q >= 1000000
      puts e
      tmp2[e] = true
    end
    if  tmp[e] >= 1000000 && tmp2[e] == false
      puts e
    end
    if  i == n-1 && (tmp.max{|a,b| a[1]<=>b[1]})[1] < 1000000
      puts "NA" 
    end
  end
end
