#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    while(1){
        char ban[10][10] = {{0}};
        char field[10][10] = {{0}};
        cin >> field[0];
        if(field[0][0] == '0') break;
        cin >> field[1];
        cin >> field[2];
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                ban[i+1][j+1] = field[i][j];
            }
        }
        for(int i = 1; i <= 3; i++){
            for(int j = 1; j <= 3; j++){
                if(i == 1){
                    int cnt = 0;
                    for(int l = 1; l <= 3; l++){
                        if(ban[i][j] == ban[l][j])cnt++;
                    }
                    if(cnt == 3){
                        printf("%c\n",ban[i][j]);
                        goto end;
                    }
                }
                if(j == 1){
                    int cnt = 0;
                    for(int l = 1; l <= 3; l++){
                        if(ban[i][j] == ban[i][l])cnt++;
                    }
                    if(cnt == 3){
                        printf("%c\n",ban[i][j]);
                        goto end;
                    }
                }
            }
        }
        printf("NA\n");
        end:;
    }
	return 0;
}