Go: package main

import (
	"bufio"
	"os"
		"strings"
	"fmt"
)

var scanner = bufio.NewScanner(os.Stdin)
const (
	allb = "bbb"
	allw = "www"
)

func main() {
	for scanner.Scan() {
		row1 := scanner.Text()
		if row1 == "0" {
			break
		}
		scanner.Scan()
		row2 := scanner.Text()
		scanner.Scan()
		row3 := scanner.Text()
		x := make([]string, 8)
		x[0] = row1
		x[1] = row2
		x[2] = row3
		for i := 0; i < 3; i++ {
			col := make([]string, 3)
			col[0] = string(row1[i])
			col[1] = string(row2[i])
			col[2] = string(row3[i])
			x[i+3] = strings.Join(col, "")
		}
		tmp := make([]string, 3)
		tmp[0] = string(row1[0])
		tmp[1] = string(row2[1])
		tmp[2] = string(row3[2])
		x[6] = strings.Join(tmp, "")
		tmp[0] = string(row1[2])
		tmp[1] = string(row2[1])
		tmp[2] = string(row3[0])
		x[7] = strings.Join(tmp, "")
		flag := false
		for _, v := range x {
			if string(v) == allb {
				fmt.Println("b")
				flag = true
				break
			} else if string(v) == allw {
				fmt.Println("w")
				flag = true
				break
			}
		}
		if !flag {
			fmt.Println("NA")
		}
	}
}

C++: #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

int x[][3]={0,1,2,0,1,2,0,1,2,0,0,0,1,1,1,2,2,2,0,1,2,0,1,2};
int y[][3]={0,0,0,1,1,1,2,2,2,0,1,2,0,1,2,0,1,2,0,1,2,2,1,0};

int main() {
	char ban[3][3];
	while(cin>>ban[0][0],ban[0][0]!='0'){
		cin>>ban[0][1]>>ban[0][2]>>ban[1][0]>>ban[1][1]>>ban[1][2]>>ban[2][0]>>ban[2][1]>>ban[2][2];
		int i;
		bool win=false;
		for(i=0;i<8;i++){
			if(ban[y[i][0]][x[i][0]]=='b'&&ban[y[i][1]][x[i][1]]=='b'&&ban[y[i][2]][x[i][2]]=='b'){cout<<"b"<<endl;win=true;}
			if(ban[y[i][0]][x[i][0]]=='w'&&ban[y[i][1]][x[i][1]]=='w'&&ban[y[i][2]][x[i][2]]=='w'){cout<<"w"<<endl;win=true;}
		}
		if(win==false)cout<<"NA"<<endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    vector<vector<char>>v(5,vc(5));
    while(cin>>v[0][0]){
        if(v[0][0]=='0')break;
        else for(int i=0; i<3;i++)
            for(int j=0; j<3;j++){
                if((i==0&&j==0))continue;
                    cin>>v[i][j];
            }
    bool flag=false; char ans = '\0';
    rep(i,3)if((v[i][0]==v[i][1])&&(v[i][1]==v[i][2])){
        flag=true;
        ans=v[i][0];
    }rep(i,3){
        if((v[0][i]==v[1][i])&&(v[1][i]==v[2][i])){
            flag=true;
            ans=v[0][i];
        }
    }if((v[0][0]==v[1][1])&&(v[1][1]==v[2][2])){flag=true; ans=v[0][0];}
    if((v[0][2]==v[1][1])&&(v[1][1]==v[2][0])){flag=true; ans=v[1][1];}
    if(flag)cout<<ans<<endl;
    else cout<<"NA"<<endl;
    }
}

C++: #include <iostream>
using namespace std;

char b[3][3];

bool check(char c) {
	for (int i = 0; i < 3; i++) {
		if (b[i][0] == c && b[i][1] == c && b[i][2] == c) return true;
		if (b[0][i] == c && b[1][i] == c && b[2][i] == c) return true;
	}
	if (b[0][0] == c && b[1][1] == c && b[2][2] == c) return true;
	if (b[0][2] == c && b[1][1] == c && b[2][0] == c) return true;
	return false;
}

int main() {
	while (true) {
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				cin >> b[i][j];
				if (b[i][j] == '0') return 0;
			}
		}

		if (check('b')) {
			cout << 'b' << endl;
		}
		else if (check('w')) {
			cout << 'w' << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
}

C++: #include<iostream>
using namespace std;
int main(void) {
	char c;
	int goban[3][3] = { 0 }, result = 0, judge = 0;
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			cin >> c;
			if (c == '0') return 0;
			if(c=='b')goban[i][j] = 1;
			else if (c == 'w')goban[i][j] = -1;
			else goban[i][j] = 0;
		}
	}
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++) {
			judge += goban[i][j];
		}
		if (judge == 3) result = 1;
		else if (judge == -3) result = -1;

		judge = 0;
	}
	for (int j = 0; j < 3; j++) {
		for (int i = 0; i < 3; i++) {
			judge += goban[i][j];
		}
		if (judge == 3) result = 1;
		else if (judge == -3) result = -1;

		judge = 0;
	}
	for (int i = 0; i < 3; i++) {
			judge += goban[i][i];
		if (judge == 3) result = 1;
		else if (judge == -3) result = -1;

		judge = 0;
	}
	for (int i = 0; i < 3; i++) {
			judge += goban[i][2-i];
		if (judge == 3) result = 1;
		else if (judge == -3) result = -1;

		judge = 0;
	}

	if (result == 1) {
		cout << "b" << endl;
	}
	else if (result == -1) {
		cout << "w" << endl;
	}
	else {
		cout << "NA" << endl;
	}

	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
string s[3];
while(cin>>s[0]){
if(s[0]=="0")break;
cin>>s[1]>>s[2];
if(s[0]=="bbb"){cout<<"b"<<endl;continue;}
if(s[1]=="bbb"){cout<<"b"<<endl;continue;}
if(s[2]=="bbb"){cout<<"b"<<endl;continue;}
if(s[0]=="www"){cout<<"w"<<endl;continue;}
if(s[1]=="www"){cout<<"w"<<endl;continue;}
if(s[2]=="www"){cout<<"w"<<endl;continue;}
if(s[0][0]==s[1][1]&&s[1][1]==s[2][2]){cout<<s[0][0]<<endl;continue;}
if(s[0][2]==s[1][1]&&s[1][1]==s[2][0]){cout<<s[0][2]<<endl;continue;}
if(s[0][0]==s[1][0]&&s[1][0]==s[2][0]){cout<<s[0][0]<<endl;continue;}
if(s[0][1]==s[1][1]&&s[1][1]==s[2][1]){cout<<s[0][1]<<endl;continue;}
if(s[0][2]==s[1][2]&&s[1][2]==s[2][2]){cout<<s[0][2]<<endl;continue;}
cout<<"NA"<<endl;
}
return 0;
}

C++: #include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

int di[][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}
};
int main(){
	string t;
	while(cin >> t , t != "0"){
		string ans = "NA";
		string s; s += t;
		rep(i,2)cin >> t , s+=t;
		rep(i,8){
			bool f = true;
			rep(j,3) f &= s[di[i][j]] == s[di[i][0]];
			if(f && s[di[i][0]] != '+'){
				ans = s[di[i][0]];
			}
		}
		cout << ans << endl;
	}
}

C++: #include<iostream>
#include<utility>
#include<queue>
#include<functional>
#include<algorithm>
#include<cstring>
#include<vector>
#include<climits>
#include<map>
using namespace std;
#define FOR(i,n) for(int i=0;i<(int)n;i++)
#define FORI(i,k,n) for(int i=k;i<(int)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define INF (2<<25)
typedef pair<int,int> pii;
typedef vector<int> vi;

int main()
{
	while(true)
	{
		string a[3];
		cin>>a[0]>>a[1]>>a[2];
		if(a[0]=="0")break;
		
		bool isdraw=true;
		
		FOR(i,3)
		{
			bool equal[2]={1,1};
			FOR(j,3)
			{
				if(a[i][j]!=a[i][0])equal[0]=false;
				if(a[j][i]!=a[0][i])equal[1]=false;
			}
			FOR(j,2)
			{
				if(equal[j]&&a[(j?0:i)][j?i:0]!='+')
				{
					isdraw=false;
					cout<<a[(j?0:i)][j?i:0]<<endl;
				}
			}
		}
		bool equal[2]={1,1};
		FOR(i,3)
		{
			if(a[i][i]!=a[0][0])equal[0]=false;
			if(a[i][2-i]!=a[0][2])equal[1]=false;
		}
		FOR(j,2)
		{
			if(equal[j]&&a[(j?0:0)][j?2:0]!='+')
			{
				isdraw=false;
				cout<<a[(j?0:0)][j?2:0]<<endl;
			}
		}
		if(isdraw)cout<<"NA"<<endl;
		
	}
}