loop
  n = gets.chomp.to_i
  break if n == 0

  sales = Hash.new(0)

  n.times do
    i, p, q = gets.chomp.split.map(&:to_i)
    value = sales[i]
    sales[i] += p * q
  end

  if sales.select { |key, value| value >= 1_000_000 }.any?
    sales.each do |key, value|
      puts key if value >= 1_000_000
    end
  else
    puts 'NA'
  end

end