#include <bits/stdc++.h>
using namespace std;

int main(){
    char field[3][3];
    while(cin >> field[0], field[0][0] != '0'){
        bool isCorrect = true;
        for(int i=1; i < 3; i++){
            cin >> field[i];
        }

        for(int i=0; i < 3; i++){
            isCorrect = true;
            char stone = field[i][0];
            for(int j=1; j < 3; j++){
                if(stone != field[i][j]) isCorrect = false;
            }
            if(isCorrect){cout << stone << endl; break;}
        }

        for(int i=0; i < 3; i++){
            isCorrect = true;
            char stone = field[0][i];
            for(int j=1; j < 3; j++){
                if(stone != field[j][i]) isCorrect = false;
            }
            if(isCorrect){cout << stone << endl; break;}
        }

        if(isCorrect) continue;

        char stone = field[0][0];

        if(stone == field[1][1] && stone == field[2][2]){cout << stone << endl; continue;}

        stone = field[2][0];

        if(stone == field[1][1] && stone == field[0][2]){cout << stone << endl; continue;}

        cout << "NA" << endl;
    }
}