#include <iostream>
#include <string>

using namespace std;

char solve(char board[9]) {
	//テァツクツヲ
	for (int i = 0; i < 3; i++)
		if (board[i] != '+' && board[i] == board[i + 3] && board[i] == board[i + 3 * 2]) 
			return board[i];

	//テヲツィツェ
	for (int i = 0; i < 9; i += 3)
		if (board[i] != '+' && board[i] == board[i + 1] && board[i] == board[i + 2])
			return board[i];

	//テヲツ鳴愿」ツつ?
	if (board[0] != '+' && board[0] == board[3 + 1] && board[0] == board[3 * 2 + 2])
		return board[0];
	if (board[2] != '+' && board[2] == board[3 + 1] && board[2] == board[3 * 2])
		return board[2];

	return 0;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	while (1) {
		char board[9];
		cin >> board[0];
		if (board[0] == '0') break;
		for (int i = 1; i < 9; i++)
			cin >> board[i];
		char c;
		if ((c = solve(board)))
			cout << c << endl;
		else
			cout << "NA" << endl;
	}
}