#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

void solve(string s){
    int x[8][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}};
    for (int i = 0; i < 8; ++i) {
        if(s[x[i][0]] == s[x[i][1]] && s[x[i][1]] == s[x[i][2]]){
            if(s[x[i][0]] != '+'){
                cout << s[x[i][0]] << "\n";
                return;
            }
        }
    }
    cout << "NA" << "\n";
    return;
}

int main() {
    string s, t, u;
    while(cin >> s, s != "0"){
        cin >> t >> u;
        solve(s+t+u);
    }
    return 0;
}
