#include <iostream>
#include <vector>
using namespace std;

int main()
{
	int n;

	while (cin >> n, n){
		long long e[5000] = {0}, p, q, t;
		bool out = false, f = false;
		vector<int> s;
		for (int i = 0; i < n; i++){
			cin >> t >> p >> q;
			for (int j = 0; j < s.size(); j++){
				if (s[j] == t){
				 	f = true;
					break;
				}
			}
			if (f == false){
				s.push_back(t);
			}
			e[t] += p * q;
		}
		for (int i = 0; i < s.size(); i++){
			if (e[s[i]] >= 1000000){
				cout << s[i] << endl;
			  out = true;
			}
		}
		if (out == false) cout << "NA" << endl;
	}
	return (0);
}
#include <iostream>
#include <string>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

string s[12];
int dx[4] = {1,0,-1,0}; 
int dy[4] = {0,1,0,-1};

void dfs(int x,int y)
{
	s[x][y] = '0';

	rep(i,4)
	{
		int nx = x + dx[i];
		int ny = y + dy[i];

		if(0 <= nx && nx < 12 && 0 <= ny && ny < 12)
		{
			if(s[nx][ny] == '1')
			{
				dfs(nx,ny);
			}
		}
	}
	return;
}


int main()
{
	while(cin >> s[0])
	{
		REP(i,1,12)
		{
			cin >> s[i];
		}

		int res = 0;
		rep(i,12)
		{
			rep(j,12)
			{
				if(s[i][j] == '1')
				{
					dfs(i,j);
					res++;
				}
			}
		}
		cout << res << endl;
	}
	return 0;
}