n = gets
how = n.to_i
until how == 0
    member = Hash.new
    how.times do
        x = gets
        y = x.split(" ")
        id = y[0].to_i
        howmuch = y[1].to_i
        howmany = y[2].to_i
        sell = howmany * howmuch
        if member.key?(id)
            member[id] += sell
        else
            member.store(id,sell)
        end
    end
    seller = member.select{|k,v| v >= 1000000}
    if seller.empty?
        puts "NA"
    else
    seller.each do |k,v|
        puts "#{k}"
    end
    end
    n = gets
    how = n.to_i
end
