sums = Hash.new(0)
overs = Hash.new 
while gets do
  n = $_.to_i
  next if n.zero?
  sums.clear
  overs.clear
  n.times do
    i, p , q = gets.split
    sums[i] += p.to_i * q.to_i
    overs[i] = sums[i] if sums[i] >= 1_000_000
  end
  puts overs.empty? ? "NA" : overs.keys
end