#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main() {
    vector<string> bd(3);
    while (cin >> bd[0], bd[0] != "0") {
        for (int i=1; i<3; ++i) cin >> bd[i];
        string res = "NA";
        for (int k=0; k<3; ++k) {
            if (bd[0][k] == bd[1][k] && bd[1][k] == bd[2][k]) res = bd[0][k];
            if (bd[k][0] == bd[k][1] && bd[k][1] == bd[k][2]) res = bd[k][0];
        }
        if (bd[0][0] == bd[1][1] && bd[1][1] == bd[2][2]) res = bd[0][0];
        if (bd[2][0] == bd[1][1] && bd[1][1] == bd[0][2]) res = bd[2][0];
        cout << res << endl;
    }
    return 0;
}