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 <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
typedef complex<double> P;

int solve(string s[3]){
  if(s[0][0] == s[0][1] && s[0][1] == s[0][2] && s[0][0] != '+') return (s[0][0] == 'w' ? 0 : 1);
  if(s[1][0] == s[1][1] && s[1][1] == s[1][2] && s[1][0] != '+') return (s[1][0] == 'w' ? 0 : 1);
  if(s[2][0] == s[2][1] && s[2][1] == s[2][2] && s[2][0] != '+') return (s[2][0] == 'w' ? 0 : 1);

  if(s[0][0] == s[1][0] && s[1][0] == s[2][0] && s[0][0] != '+') return (s[0][0] == 'w' ? 0 : 1);
  if(s[0][1] == s[1][1] && s[1][1] == s[2][1] && s[0][1] != '+') return (s[0][1] == 'w' ? 0 : 1);
  if(s[0][2] == s[1][2] && s[1][2] == s[2][2] && s[0][2] != '+') return (s[0][2] == 'w' ? 0 : 1);

  if(s[0][0] == s[1][1] && s[1][1] == s[2][2] && s[0][0] != '+') return (s[0][0] == 'w' ? 0 : 1);
  if(s[0][2] == s[1][1] && s[1][1] == s[2][0] && s[0][2] != '+') return (s[0][2] == 'w' ? 0 : 1);

  return -1;
}
 
int main() {
  string s[3];
  while(cin >>s[0] && s[0] != "0"){
    cin >>s[1] >>s[2];
    int ans = solve(s);
    if(ans == 0) cout <<"w" <<endl;
    else if(ans == 1) cout <<"b" <<endl;
    else cout <<"NA" <<endl;
  }
  return 0;
}

C++: #include <iostream>

int main()
{
	char board[3][3];
	while (true) {
		std::cin >> board[0][0];
		if (board[0][0] == '0') break;
		std::cin >> board[0][1] >> board[0][2];
		std::cin >> board[1][0] >> board[1][1] >> board[1][2];
		std::cin >> board[2][0] >> board[2][1] >> board[2][2];
		char c;
		bool isNA = true;
		// vertical
		for (int j=0; j<3; j++) {
			c = board[0][j];
			if (c == '+') continue;
			if (board[1][j] == c && board[2][j] == c) {
				std::cout << c << std::endl;
				isNA = false; break;
			}
		}
		// horizontal
		if (isNA) {
			for (int i=0; i<3; i++) {
				c = board[i][0];
				if (c == '+') continue;
				if (board[i][1] == c && board[i][2] == c) {
					std::cout << c << std::endl;
					isNA = false; break;
				}
			}
		}
		// diagonal
		if (isNA) {
			c = board[1][1];
			if (c != '+') {
				if (board[0][0] == c && c == board[2][2]) {
					std::cout << c << std::endl;
					isNA = false;
				}
				else if (board[2][0] == c && c == board[0][2]) {
					std::cout << c << std::endl;
					isNA = false;
				}
			}
		}
		if (isNA) std::cout << "NA" << std::endl;
	}
	return 0;
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    while(1){
        char ban[10][10] = {{0}};
        char field[10][10] = {{0}};
        cin >> field[0];
        if(field[0][0] == '0') break;
        cin >> field[1];
        cin >> field[2];
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                ban[i+1][j+1] = field[i][j];
            }
        }
        for(int i = 1; i <= 3; i++){
            for(int j = 1; j <= 3; j++){
                if(i == 1){
                    int cnt = 0;
                    for(int l = 1; l <= 3; l++){
                        if(ban[i][j] == ban[l][j])cnt++;
                    }
                    if(cnt == 3 && ban[i][j] != '+'){
                        printf("%c\n",ban[i][j]);
                        goto end;
                    }
                }
                if(j == 1){
                    int cnt = 0;
                    for(int l = 1; l <= 3; l++){
                        if(ban[i][j] == ban[i][l])cnt++;
                    }
                    if(cnt == 3 && ban[i][j] != '+'){
                        printf("%c\n",ban[i][j]);
                        goto end;
                    }
                }
            }
        }
        if(ban[1][1] == ban[2][2] && ban[2][2] == ban[3][3] && ban[1][1] != '+'){
            printf("%c\n",ban[1][1]);
            goto end;
        }
        else if(ban[1][3] == ban[2][2] && ban[2][2] == ban[3][1] && ban[1][3] != '+'){
            printf("%c\n",ban[1][3]);
            goto end;
        }
        printf("NA\n");
        end:;
    }
	return 0;
}

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;
		bool end=false;
		FOR(i,3)
		{
			bool equal[2]={1,1};
			if(end)break;
			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;
					end=true;
					break;
				}
			}
		}
		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(end)break;
			if(equal[j]&&a[(j?0:0)][j?2:0]!='+')
			{
				isdraw=false;
				cout<<a[(j?0:0)][j?2:0]<<endl;
				end=true;
				break;
			}
		}
		if(isdraw)cout<<"NA"<<endl;
	}
}

C++: #include<iostream>
using namespace std;
int main(void) {
	while (1) {
		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;
		}
	}
}