#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	int pat[][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 },
	};

	char buf[16];
	char s[16];
	while (cin.getline(buf, sizeof(buf)), *buf != '0')
	{
		s[0] = '\0';
		strcat(s, buf);
		for (int i = 0; i < 2; ++i)
		{
			cin.getline(buf, sizeof(buf));
			strcat(s, buf);
		}

		char win = '+';
		for (int i = 0; i < 8 && win == '+'; ++i)
			if (s[pat[i][0]] == s[pat[i][1]] && s[pat[i][1]] == s[pat[i][2]])
				win = s[pat[i][0]];

		if (win != '+')
			printf("%c\n", win);
		else
			puts("NA");
	}

	return 0;
}