#include<cstdio>
#include<algorithm>
using namespace std;
int f(int a,int b,int c)
{
	if(a==b&&b==c&&a-'+')return a;
	return 0;
}
int main()
{
	char s[10];
	int i,c;
	while(c=0,scanf("%s",s),s[0]-'0')
	{
		scanf("%s%s",&s[3],&s[6]);
		for(i=0;i<3;++i)c=max(max(c,f(s[i*3],s[i*3+1],s[i*3+2])),f(s[i],s[i+3],s[i+6]));
		c=max(c,max(f(s[0],s[4],s[8]),f(s[2],s[4],s[6])));
		if(c)printf("%c\n",c);
		else puts("NA");
	}
	return 0;
}