while true do
  n = gets.to_i
  break if n == 0

  hash = {}
  syachiku = {}
  n.times do |i|
    no, kakaku, kosu = gets.chop.split.map(&:to_i)
    hash[no] = hash.key?(no) ? hash[no] + kakaku * kosu : kakaku * kosu
    if hash[no] >= 1000000 then
      syachiku[no] = true
    end
  end
  if syachiku.keys.count == 0 then
    puts "NA"
  else
    syachiku.keys.each do |k|
      puts k
    end
  end
end
