#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int di[][3] = {
	{0,1,2},{3,4,5},{6,7,8},
	{0,3,6},{1,4,7},{2,5,8},
	{0,4,8},{2,4,6}
};
int main(){
	string t;
	while(cin >> t , t != "0"){
		string ans = "NA";
		string s; s += t;
		rep(i,2)cin >> t , s+=t;
		rep(i,8){
			bool f = true;
			rep(j,3) f &= s[di[i][j]] == s[di[i][0]];
			if(f && s[di[i][0]] != '+'){
				ans = s[di[i][0]];
			}
		}
		cout << ans << endl;
	}
}