while gets do
  n = $_.chomp.to_i
  next if n == 0
  sums = Hash.new(0)
  n.times do
    i, p , q = gets.split
    sums[i] += p.to_i * q.to_i
  end
  sums.delete_if{|k, v| v < 1_000_000}
  if sums.size == 0
    puts "NA"
  else
    puts sums.keys.sort
  end
end