
while line = gets do
  break if line.chomp == "0"

  n = line.chomp.to_i
  is_na = true

  h = {}
  h.default = 0

  n.times do
    l = gets.chomp.split(' ')
    i = l[0]
    p = l[1]
    q = l[2]

    h[i] = h[i].to_i + (p.to_i * q.to_i)
  end

  h.each do |k,v|
    if v.to_i >= 1000000 then
      puts k + "\n"
      is_na = false
    end
  end

  puts "NA" if is_na == true

end