inputs = readlines

hash = Hash.new(0)

inputs.map(&:chomp).each do |line|
  nums = line.split(' ')
  nums.map!(&:to_i)

  if nums.size == 1
    unless hash.empty?
      no_user = true
      hash.each do |k,v|
        if v >= 1_000_000
          puts k
          no_user = false
        end
      end
      puts "NA" if no_user
      hash.clear
    end
    exit if nums[0].zero?
  else nums.size == 3
    hash[ nums[0] ] += (nums[1] * nums[2])
  end
end
