using System;
using System.Collections;

public class p0100
{
	p0100 ()
	{
		string str;
		string[] st;
		int n, p;
		bool f;
		ArrayList al = new ArrayList ();
		decimal[] sm = new decimal[4001];
		
		while ((str=Console.ReadLine())!=null && str != "0") {
			n = int.Parse (str);
			f = true;
			for (int i = 0; i < 4001; ++i)
				sm [i] = 0;
			
			while (0 < n--) {
				st = (Console.ReadLine ()).Split (' ');
				p = int.Parse (st [0]);
				
				sm [p] += decimal.Parse (st [1]) * decimal.Parse (st [0]);
				if (!al.Contains (p))
					al.Add (p);
			}
			
			foreach (int i in al)
				if (sm [i] >= 1000000) {
					Console.WriteLine ("{0}", i);
					f = false;
				}
			if (f)
				Console.WriteLine ("NA");
			al.Clear();
		}
	}
	
	public static int Main(string[] args){
		new p0100();
		return 0;
	}
}