#include <iostream>
#include <fstream>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <complex>
#include <cstdio>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

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

int l[][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}};
char c[9];

int main(){
	while(cin>>c[0]&&c[0]-'0'){
		rep(i,8)cin>>c[i+1];
		string ans="NA";
		rep(i,8)if(c[l[i][0]]!='+'&&c[l[i][0]]==c[l[i][1]]&&c[l[i][0]]==c[l[i][2]])ans=c[l[i][0]];
		cout<<ans<<endl;
	}
}