while (n = gets.to_i) != 0 do
  arr = Array.new(4001, 0)
  n.times do
    num, tanka, ryou = gets.split.map(&:to_i)
    arr[num] += tanka * ryou
  end

  if arr.all?{ |a| a < 1000000 }
    puts "NA"
  else
    arr.each_with_index do |a, i|
      puts i if a >= 1000000
    end
  end
end