while gets do
  n = $_.to_i
  next if n.zero?
  sums = {}
  n.times do
    i, p , q = gets.split
    sums[i] += p.to_i * q.to_i if sums[i] ||= 0
  end
  sums.delete_if{|k, v| v < 1_000_000}
  puts sums.empty? ? "NA" : sums.keys
end