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++: #define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,string> P;

static const double eps = 1e-8;

int main(){
	char table[5][5];
	while(~scanf("%s",table)){
		if(table[0][0] == '0') break;
		for(int i=1;i<=2;i++){
			scanf("%s",table+i);
		}

		int winner=0;
		for(int i=0;i<3;i++){
			int a=0,b=0;
			for(int j=0;j<3;j++){
				if(table[i][j] == 'a') a++;
				if(table[i][j] == 'b') b++;
			}
			if(a==3) winner = 1;
			if(b==3) winner = -1;
		}

		for(int i=0;i<3;i++){
			int a=0,b=0;
			for(int j=0;j<3;j++){
				if(table[j][i] == 'a') a++;
				if(table[j][i] == 'b') b++;
			}
			if(a==3) winner = 1;
			if(b==3) winner = -1;
		}

		if(table[0][0] == table[1][1]
		&& table[1][1] == table[2][2]
		&& table[2][2] =='a') winner = 1;

		if(table[0][0] == table[1][1]
		&& table[1][1] == table[2][2]
		&& table[2][2] =='b') winner = -1;

		printf("%s\n", winner == 1 ? "a" : winner == -1 ? "b" : "NA");

	}
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
int main() {
  while(1){
    int i;
    char a[5][5]={};
    bool ans=false;
    cin>>a[0];
    if(a[0][0]=='0')break;
    cin>>a[1];
    cin>>a[2];
    rep(i,3)
      if(a[i][0]==a[i][1] && a[i][1]==a[i][2] && a[i][0]!='+')
        cout<<a[i][0]<<endl,ans=true;
      else if(a[0][i]==a[1][i] && a[1][i]==a[2][i] && a[0][i]!='+')
        cout<<a[0][i]<<endl,ans=true;
    if(ans)continue;
    if((a[0][0]==a[1][1] && a[1][1]==a[2][2] && a[0][0]!='+')||
       (a[0][2]==a[1][1] && a[1][1]==a[2][0] && a[1][1]!='+'))
      cout<<a[1][1]<<endl;
    else
      cout<<"NA"<<endl;
  }
}

C++: // #define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;

#define MP make_pair
#define fastIO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (未test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}

// ------------------- include, typedef, define END. -------------------

string solve(vector<vector<char> > in){
	char mozi[3] = { 'b', 'w', '+' };
	string ret;
	FOR(i, 0, 3){
		FOR(j, 0, 3){
			bool flg = true;
			// 横に見る
			FOR(k, 0, 3){
				if (in[j][k] != mozi[i]){
					flg = false;
				}
			}
			if (flg)
				if (mozi[i] != '+')
					return ret=mozi[i];
			
			// 縦に見る
			flg = true;
			FOR(k, 0, 3){
				if (in[k][j] != mozi[i]){
					flg = false;
				}
			}
			if (flg)
				if (mozi[i] != '+')
					return ret = mozi[i];
		}
	}
	// 斜めに見る
	FOR(i, 0, 3){
		bool flg = true;
		for (int j = 0, k = 0; j < 3, k < 3; j++, k++){
			if (in[j][k] != mozi[i])
				flg = false;
		}
		if (flg)
			if (mozi[i] != '+')
				return ret = mozi[i];

		flg = true;
		for (int j = 2, k = 0; j >=0, k <3; j--, k++){
			if (in[j][k] != mozi[i])
				flg = false;
		}
		if (flg)
			if (mozi[i] != '+')
				return ret = mozi[i];
	}
	return "NA";
}

int main(){
	int n = 0;
	string firstLine;

	while (getline(cin, firstLine), firstLine != "0"){
		vector<vector<char> > in(3,vector<char>(3));
		// 最初の行
		istringstream stream(firstLine);
		char temp;
		int count = 0;
		while (stream >> temp,!stream.eof()){
			in[0][count] = temp;
			count++;
		}
		// 2行目・3行目
		FOR(i, 1, 3){
			FOR(j, 0, 3){
				cin >> temp;
				in[i][j] = temp;
			}
		}
		cout << solve(in) << endl;
		//cin >> temp; 
		cin.ignore();
	}

	return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
bool b00l;
void check(char c) {
	if (c == 'b') { cout << "b\n"; b00l = true; }
	else if (c == 'w') { cout << "w\n"; b00l = true; }
	return;
}
int main() {
	string a, b, c;
	while (cin >> a) {
		if (a.size() == 1)return 0;
		cin >> b >> c;
		b00l = false;
		if (a[0] == a[1] && a[1] == a[2])check(a[0]);
		if (b[0] == b[1] && b[1] == b[2])check(b[0]);
		if (c[0] == c[1] && c[1] == c[2])check(c[0]);
		if (a[0] == b[0] && b[0] == c[0])check(a[0]);
		if (a[1] == b[1] && b[1] == c[1])check(a[1]);
		if (a[2] == b[2] && b[2] == c[2])check(a[2]);
		if (a[0] == b[1] && b[1] == c[2])check(a[0]);
		if (c[0] == b[1] && b[1] == a[2])check(a[2]);
		if (!b00l)cout << "NA\n";
	}
}

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,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++){
     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(yoko1 == 3 || tate1 == 3){
	ans = 1;
	break;
      }
      else if(yoko2 == 3 || tate2 == 3){
	ans = 2;
	break;
      }
    }

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

  }
  return 0;
}