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>
using namespace std;
int main(){
	string m[3];
	while(std::cin >> m[0], m[0][0] != '0'){
		for(int i=1;i<3;i++)std::cin >> m[i];
		string w = "NA";
		for(int i=0;i<3;i++){
			if(m[i][0] == m[i][1] && m[i][0] == m[i][2])
				w = m[i][0];
			if(m[0][i] == m[1][i] && m[0][i] == m[2][i])
				w = m[0][i];
		}
		if(m[0][0] == m[1][1] && m[0][0] == m[2][2])
			w = m[0][0];
		if(m[0][2] == m[1][1] && m[0][2] == m[2][0])
			w = m[0][2];
		
		if(w == "+")w = "NA";
		
		std::cout << w << std::endl;
	}
}

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

string s[9];
int dx[] = {0,0,1,-1,1,1-1,-1};
int dy[] = {1,-1,0,0,-1,1,-1,1};
int k;

bool solve(char c, int p, int y, int x){
  if(y < 0 || x < 0 || y == 3 || x == 3) return false;
  if(c != s[y][x] || c == '+') return false;
  if(p == 3) return true;
  solve(c, p+1, y+dy[k], x+dx[k]);
}

int main(){

  while(true){
    cin >> s[0];
    if(s[0] == "0") break;
    cin >> s[1] >> s[2];

    char c = '@';
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
	for(k=0;k<4;k++) if(solve(s[i][j], 1, i, j)) c = s[i][j];
      }
    }
    
    if(c == '@') cout << "NA" << endl;
    else cout << c << endl;
    
  }
}

C++: #include <iostream>

using namespace std;
int main(void){
	char t[10];
	string s,s1,s2,s3;
	while(getline(cin,s1)){
		if(s1=="0") break;
		getline(cin,s2);
		getline(cin,s3);
		s=s1+s2+s3;
		for(int i=0;i<9;++i) t[i]=s[i];
		bool o[10],x[10];
		int i;
		for(i=0;i<9;++i){
			o[i]=(t[i]=='b')?true:false;
			x[i]=(t[i]=='w')?true:false;
		}
		int ans = 2;
		for(i=0;i<3;++i){
			if(o[i*3]&&o[i*3+1]&&o[i*3+2]||o[i]&&o[3*1+i]&&o[3*2+i]) ans=0;
			if(x[i*3]&&x[i*3+1]&&x[i*3+2]||x[i]&&x[3*1+i]&&x[3*2+i]) ans=1;
		}
		if(o[0]&&o[4]&&o[8]||o[2]&&o[4]&&o[6]) ans=0;
		if(x[0]&&x[4]&&x[8]||x[2]&&x[4]&&x[6]) ans=1;
		cout<<((ans<2)?((ans)?"w":"b"):"NA")<<endl;
	}
	return 0;
}

C++: #include <stdio.h>
#pragma warning(disable : 4996)
char c[10]; const char d[3] = "bw";
int main() {
	while (~scanf("%c", &c[0])) {
		if (c[0] == '0') break;
		for (int i = 1; i < 9; i++) {
			if (i % 3 == 0) getchar();
			scanf("%c", &c[i]);
		}
		bool ok = false;
		for (int i = 0; i < 2; i++) {
			bool flag = false;
			if (c[0] == d[i] && c[1] == d[i] && c[2] == d[i]) flag = true;
			if (c[3] == d[i] && c[4] == d[i] && c[5] == d[i]) flag = true;
			if (c[6] == d[i] && c[7] == d[i] && c[8] == d[i]) flag = true;
			if (c[0] == d[i] && c[3] == d[i] && c[6] == d[i]) flag = true;
			if (c[1] == d[i] && c[4] == d[i] && c[7] == d[i]) flag = true;
			if (c[2] == d[i] && c[5] == d[i] && c[8] == d[i]) flag = true;
			if (c[0] == d[i] && c[4] == d[i] && c[8] == d[i]) flag = true;
			if (c[2] == d[i] && c[4] == d[i] && c[6] == d[i]) flag = true;
			if (flag) {
				ok = true; printf("%c\n", d[i]); break;
			}
		}
		if (!ok) printf("NA\n"); getchar();
	}
	return 0;
}

C++: #include <iostream>
int main(){
	std::string m[3];
	while(std::cin >> m[0], m[0][0] != '0'){
		for(int i=1;i<3;i++)std::cin >> m[i];
		std::string w = "NA";
		for(int i=0;i<3;i++){
			if(!(m[i][0] + m[i][1] - m[i][2] * 2))
				if(m[i][0] != '+')w = m[i][0];
			if(!(m[0][i] + m[1][i] - m[2][i] * 2))
				if(m[0][i] != '+')w = m[0][i];
		}
		if(!(m[0][0] + m[1][1] - m[2][2] * 2))
			if(m[0][0] != '+')w = m[0][0];
		if(!(m[0][2] + m[1][1] - m[2][0] * 2))
			if(m[0][2] != '+')w = m[0][2];
		
		std::cout << w << std::endl;
	}
}

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

int main()
{
	while (1) {
		string a;
		cin >> a;
		if (a == "0")break;
		string b, c;
		cin >> b >> c;
		a += b + c;
		if (a[4] != '+' && (a[0] == a[4] && a[4] == a[8] || a[1] == a[4] && a[4] == a[7] || a[2] == a[4] && a[4] == a[6] || a[3] == a[4] && a[4] == a[5]))cout << a[4] << endl;
		else 	if (a[0] != '+' && (a[0] == a[1] && a[1] == a[2] || a[0] == a[3] && a[3] == a[6]))cout << a[0] << endl;
		else 	if (a[8] != '+' && (a[6] == a[7] && a[7] == a[8] || a[2] == a[5] && a[5] == a[8]))cout << a[8] << endl;
		else cout << "NA" << endl;
	}
}

C++: #include <stdio.h>
#include<math.h>
#include <algorithm>
using namespace std;

int main(){
	char table[3][4];
	bool FLG;

	while(true){
		scanf("%s",table[0]);
		if(table[0][0] == '0')break;

		scanf("%s",table[1]);
		scanf("%s",table[2]);

		FLG = false;

		//?¨???¨????????????
		for(int i=0; i < 3; i++){
			if((table[i][0] == 'b' || table[i][0] == 'w') && table[i][0] == table[i][1] &&
					table[i][0] == table[i][2]){
				printf("%c\n",table[i][0]);
				FLG = true;
				break;
			}

			if((table[0][i] == 'b' || table[0][i] == 'w') && table[0][i] == table[1][i] &&
					table[0][i] == table[2][i]){
				printf("%c\n",table[0][i]);
				FLG = true;
				break;
			}
		}

		if(!FLG){
			if((table[0][0] == 'b' || table[0][0] == 'w') && table[0][0] == table[1][1] &&
					table[0][0] == table[2][2]){
				printf("%c\n",table[0][0]);
				FLG = true;
				break;
			}

			if((table[0][2] == 'b' || table[0][2] == 'w') && table[0][2] == table[1][1] &&
					table[0][2] == table[2][0]){
				printf("%c\n",table[0][2]);
				FLG = true;
				break;
			}
		}

		if(!FLG)printf("NA\n");

	}

    return 0;
}