while 0 != n = gets.to_i do
  map = Hash.new(0)
  n.times do
    id, cost, vol = gets.split.map(&:to_i)
    map[id] += cost * vol
  end
  map.sort{|a, b| b <=> a}
  z = map.select{|k, v| v >= 1000000}.each{|a, b| puts a}
  puts "NA" if z.empty?
end