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 <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;
}

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

char T[3][3];

string blackwhite() {
	for (int i = 0; i < 3; i++) {
		if (T[i][0] == T[i][1] && T[i][1] == T[i][2]) {
			if (T[i][0] == 'b') { return "b"; }
			if (T[i][0] == 'w') { return "w"; }
		}
	}
	for (int i = 0; i < 3; i++) {
		if (T[0][i] == T[1][i] && T[1][i] == T[2][i]) {
			if (T[0][i] == 'b') { return "b"; }
			if (T[0][i] == 'w') { return "w"; }
		}
	}
	if (T[0][0] == T[1][1] && T[1][1] == T[2][2]) {
		if (T[0][0] == 'b') { return "b"; }
		if (T[0][0] == 'w') { return "w"; }
	}
	if (T[0][2] == T[1][1] && T[1][1] == T[2][0]) {
		if (T[0][0] == 'b') { return "b"; }
		if (T[0][0] == 'w') { return "w"; }
	}
	return "NA";
}

int main() {
	while (true) {
		cin >> T[0][0];
		if (T[0][0] == '0') { break; }
		cin >> T[0][1];
		cin >> T[0][2];
		for (int i = 1; i < 3; i++) {
			for (int j = 0; j < 3; j++){
				cin>>T[i][j];
			}
		}
		cout << blackwhite() << endl;
	}
}

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];

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

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

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

		if(B[1][1] != B[i][2-i]) {
			ok = false;
		}

		if(ok) 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 == '+') printf("NA\n");
		else printf("%c\n", a);
	}
}

C++: #include<iostream>
using namespace std;
int main(void){
    for(;;){
    char a[3][3];
    int f=0,z=0;
    for (int i=0;i<3;i++){
        cin>>a[i];
        if(a[i][0]=='0'){
            z++;
            break;
        }
        }
        if(z!=0)break;

    for(int i=0;i<1;i++){
        for(int j=0;j<3;j++){
            if(a[i][j]!='+'){
                if(a[0][j]==a[1][j]&&a[1][j]==a[2][j]){
                    cout<<a[0][j]<<endl;
                    f++;
                    goto c;
                }
            }
        }
    }
    for(int j=0;j<1;j++){
        for(int i=0;i<3;i++){
            if(a[i][j]!='+'){
                if(a[i][0]==a[i][1]&&a[i][1]==a[i][2]){
                    cout<<a[i][0]<<endl;
                    f++;
                    goto c;
                }
            }
        }
    }
    if(a[0][0]!='+'){
        if(a[0][0]==a[1][1]&&a[1][1]==a[2][2]){
            cout<<a[0][0]<<endl;
            f++;
            goto c;
        }

    }
    if(a[0][2]!='+'){
        if(a[0][2]==a[1][1]&&a[1][1]==a[2][0]){
            cout<<a[0][2]<<endl;
            f++;
            goto c;
        }
    }

    if(f==0)cout<<"NA"<<endl;
    c:;


    }
    return 0;
}

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

int main(void)
{
	string board[3];
	string set[2];
	string y_comp;
	string t_comp;
	string l_comp;
	string r_comp;
	char str[4];
	bool flag = false;
	
	set[0] = "bbb";
	set[1] = "www";
	
	while (1){
		for (int i = 0; i < 3; i++){
			scanf("%s", str);
			if (str[0] == '0') {
				flag = true;
				break;
			}
			board[i] = str;					
		}
		if (flag) break;
		
		for (int i = 0; i < 3; i++){
			for (int j = 0; j < 3; j++){
				y_comp += board[i][j];
				t_comp += board[j][i];
				if (i + j == 2) l_comp += board[i][j];
			}
			if (y_comp == set[0] || t_comp == set[0]) printf("b\n");
			else if (y_comp == set[1] || t_comp == set[1]) printf("w\n");
			else puts("NA");
			y_comp.clear();
			t_comp.clear();
			
			r_comp += board[i][i];
		}
		if (r_comp == set[0] || l_comp == set[0]) printf("b\n");
		else if (r_comp == set[1] || l_comp == str[1]) printf("w\n");
		puts("NA");
	}
	
	return (0);
}

C++: #include <cstdio>
#include <iostream>
#include <string>
using namespace std;
int a[3][3];

void bw(string str,int n){
  for(int i=0;i<3;i++){
    if(str[i] == 'b') a[n][i] = 1;
    else if(str[i] == 'w') a[n][i] = 2;
    else if(str[i] == '+') a[n][i] = 0;
  }
}

int main(){
  int i,j,tate1,tate2,yoko1,yoko2,na1,na2,nan1,nan2,ans;
  string str;
  while(1){
    cin >> str;
    if(str == "0") break;
    bw(str,0);

    for(i=1;i<3;i++){
      cin >> str;
      bw(str,i);
    }

    ans = 0;
    for(i=0;i<3;i++){
     nan1 = nan2 = na1 = na2 = tate1 = yoko1 = tate2 = yoko2 = 0;
      for(j=0;j<3;j++){
	if(a[i][j] == 1) yoko1++;
	else if(a[i][j] == 2) yoko2++;
	if(a[j][i] == 1) tate1++;
	else if(a[j][i] == 2) tate2++;
	if(a[j][j] == 1) na1++;
	else if(a[j][j] == 2) na2++;
	if(a[2-j][j] == 1) nan1++;
	else if(a[2-j][j] == 2) nan2++;
      }
      if(yoko1 == 3 || tate1 == 3 || na1 == 3 || nan1 == 3){
	ans = 1;
	break;
      }
      else if(yoko2 == 3 || tate2 == 3 || na2 == 3 || nan2 == 3){
	ans = 2;
	break;
      }
    }

    if(ans == 2) cout << "w" << endl;
    else if(ans == 1) cout << "b" << endl;
    else cout << "NA" << endl;

  }
  return 0;
}