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 <bits/stdc++.h>
using namespace std;

int main(){
    char field[3][3];
    while(cin >> field[0], field[0][0] != '0'){
        bool isCorrect = true;
        for(int i=1; i < 3; i++){
            cin >> field[i];
        }

        for(int i=0; i < 3; i++){
            isCorrect = true;
            char stone = field[i][0];
            if(stone == '+') continue;
            for(int j=1; j < 3; j++){
                if(stone != field[i][j]) isCorrect = false;
            }
            if(isCorrect){cout << stone << endl; break;}
        }

        for(int i=0; i < 3; i++){
            isCorrect = true;
            char stone = field[0][i];
            if(stone == '+') continue;
            for(int j=1; j < 3; j++){
                if(stone != field[j][i]) isCorrect = false;
            }
            if(isCorrect){cout << stone << endl; break;}
        }

        if(isCorrect) continue;

        char stone = field[0][0];

        if(stone == field[1][1] && stone == field[2][2] && stone != '+'){cout << stone << endl; continue;}

        stone = field[2][0];

        if(stone == field[1][1] && stone == field[0][2] && stone != '+'){cout << stone << endl; continue;}

        cout << "NA" << endl;
    }
}

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

int main() {
    for(string s1, s2, s3; cin >> s1, s1 != "0"; ) {
        cin >> s2 >> s3;
        string s = s1 + s2 + s3;
        string bit[] = {
            "111000000",
            "000111000",
            "000000111",
            "100100100",
            "010010010",
            "001001001",
            "100010001",
            "001010100"
        };

        int winner = -1;
        for(int i = 0; i < 8; i++) {
            string t;
            for(int j = 0; j < 8; j++) {
                if(bit[i][j] == '1') t.push_back(s[j]);
            }
            if(t[0] == 'w' && t[1] == 'w' && t[2] == 'w') winner = 0;
            if(t[0] == 'b' && t[1] == 'b' && t[2] == 'b') winner = 1;
        }
        if(winner == 0) {
            cout << 'w' << endl;
        }
        else if(winner == 1) {
            cout << 'b' << endl;
        }
        else {
            cout << "NA" << endl;
        }
    }
}

C++: #include <bits/stdc++.h>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define repb(i,a,b) for(int i=a;i>=b;i--)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define int long long
#define fi first
#define se second
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

signed main(){
	string s[3];
	while(1){
		cin>>s[0];
		if(s[0]=="0") break;
		cin>>s[1]>>s[2];
		string ans="NA";
		rep(i,0,3){
			if(s[i][0]==s[i][1] && s[i][1]==s[i][2] && s[i][0]!='+') ans=s[i][0];
			if(s[0][i]==s[1][i] && s[1][i]==s[2][i] && s[0][i]!='+') ans=s[0][i];
		}
		if(s[0][0]==s[1][1] && s[1][1]==s[2][2] && s[0][0]!='+') ans=s[0][0];
		if(s[0][2]==s[1][1] && s[1][1]==s[2][0] && s[0][2]!='+') ans=s[0][2];
		cout<<ans<<endl;
	}
}

C++: #include<iostream>
#include<cstdio>

using namespace std;

int main()
{
	
	for(;;){
		char ban[3][3];
		char result = 'N';
		
		for(int i = 0; i < 3; i++){
			for(int j = 0; j < 3; j++){
				cin >> ban[i][j];
				if(ban[i][j] == '0'){
					goto FIN;
				}
			}
		}
		
		for(int i = 0; i < 3; i++){
			if(ban[i][0] == ban[i][1] && ban[i][1] == ban[i][2]){	//ツ可。ツ板サツ津ィ
				if(ban[i][0] == 'b'){
					result = 'b';
				}
				else if(ban[i][0] == 'w'){
					result = 'w';
				}
			}
		}
		for(int i = 0; i < 3; i++){
			if(ban[0][i] == ban[1][i] && ban[1][i] == ban[2][i]){	//ツ可。ツ板サツ津ィ
				if(ban[0][i] == 'b'){
					result = 'b';
				}
				else if(ban[0][i] == 'w'){
					result = 'w';
				}
			}
		}
		
		if(ban[0][0] == ban[1][1] && ban[1][1] == ban[2][2]){	//ツづ按づ按づ淞板サツ津ィ
			if(ban[0][0] == 'b'){
				result = 'b';
			}
			else if(ban[0][0] == 'w'){
				result = 'w';
			}
		}
		if(ban[0][2] == ban[1][1] && ban[1][1] == ban[2][0]){	//ツづ按づ按づ淞板サツ津ィ
			if(ban[0][2] == 'b'){
				result = 'b';
			}
			else if(ban[0][2] == 'w'){
				result = 'w';
			}
		}
		
		if(result == 'N'){
			cout << "NA" << endl;
		}
		else{
			cout << result << endl;
		}
	}
	FIN:;
	getchar();
	return 0;
}

C++: #include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

char B[3][3];

bool isbw(char c) {
	return c == 'b' || c == 'w';
}

char check() {
	bool ok = false;
	rep(i,3) {
		if(!isbw(B[i][0])) continue;
		ok = true;
		rep(j,3) {
			if(B[i][0] != B[i][j]) {
				ok = false;
				break;
			}
		}
		if(ok) return B[i][0];
	}

	rep(i,3) {
		if(!isbw(B[0][i])) continue;
		ok = true;
		rep(j,3) {
			if(B[0][i] != B[j][i]) {
				ok = false;
				break;
			}
		}
		if(ok) return B[0][i];
	}

	ok = true;
	rep(i,3) {
		if(B[1][1] != B[i][i]) {
			ok = false;
			break;
		}
	}
	if(ok && isbw(B[1][1])) return B[1][1];

	ok = true;
	rep(i,3) {
		if(B[1][1] != B[i][2-i]) {
			ok = false;
			break;
		}
	}
	if(ok && isbw(B[1][1])) return B[1][1];
	
	return '+';
}

int main() {
	while( 1 ) {
		rep(i,3) {
			rep(j,3) {
				cin >> B[i][j];
				if(i==0 && j==0 && B[i][j] == '0') return 0;
			}
		}

		char a = check();
		if(a != 'b' && a != 'w') printf("NA\n");
		else printf("%c\n", a);
	}
}

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];
		if(a[0]=="0")break;
		cin>>a[1]>>a[2];
		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;
		
	}
}