while true
    n = gets.to_i
    break if n == 0
    h = Hash.new{|h, k| h[k] = [0, nil, nil]}
    n.times{|i|
        e, p, q = gets.chomp.split.map(&:to_i)
        h[e][0] += p * q
        h[e][1] = e if h[e][1].nil?
        h[e][2] = i if h[e][2].nil?
    }
    arr = []
    h.values.sort_by{|t, n, i| i}.each{|total, number, index| arr << number if total >= 1_000_000}
    puts (arr.empty?) ? "NA" : arr
end
