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 <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s[3];

int main(){
	while (cin >> s[0]){
		bool f1 = 0, f2 = 0;
		if (s[0] == "0")break;
		cin >> s[1] >> s[2];
		REP(i, 3){
			if (s[i][0] == s[i][1] && s[i][1] == s[i][2]){
				if (s[i][0] == 'w')f1 = 1;
				if (s[i][0] == 'b')f2 = 1;
			}
			if (s[0][i] == s[1][i] && s[1][i] == s[2][i]){
				if (s[0][i] == 'w')f1 = 1;
				if (s[0][i] == 'b')f2 = 1;
			}
		}
		if (s[0][0] == s[1][1] && s[1][1] == s[2][2]){
			if (s[0][0] == 'w')f1 = 1;
			if (s[0][0] == 'b')f2 = 1;
		}
		if (s[0][2] == s[1][1] && s[1][1] == s[2][0]){
			if (s[0][2] == 'w')f1 = 1;
			if (s[0][2] == 'b')f2 = 1;
		}
		if (f1)cout << "w" << endl;
		else if (f2)cout << "b" << endl;
		else cout << "NA" << endl;
	}
}

C++: #include <iostream>

using namespace std;

int checkYoko( char stage[4][4], int i )
{
	if( stage[i][0] == stage[i][1] && stage[i][1] == stage[i][2] ) {
		if( stage[i][0] == 'b' ) return 1;
		else if( stage[i][0] == 'w' ) return 2;
		else return 0;
	}

	return 0;
}

int checkTate( char stage[4][4], int i )
{
	if( stage[0][i] == stage[1][i] && stage[1][i] == stage[2][i] ) {
		if( stage[0][i] == 'b' ) return 1;
		else if( stage[0][i] == 'w' ) return 2;
		else return 0;
	}

	return 0;
}


int main(int argc, char const* argv[])
{
	char stage[4][4];

	while( cin >> stage[0] && stage[0][0] != '0' ){
		for( int i = 1;i < 3;i++ ) cin >> stage[i];

		int i;
		for( i = 0;i < 3;i++ ) {
			int answer = checkYoko( stage, i );
			
			if( answer == 0 ) {
				answer = checkTate( stage, i );
			}

			if( answer == 1 ){
				cout << 'b' << endl;
				break;
			} else if( answer == 2 ){
				cout << 'w' << endl;
				break;
			} else {
				if( stage[0][0] == stage[1][1] && stage[1][1] == stage[2][2] && stage[0][0] != '+' || stage[2][0] == stage[1][1] && stage[1][1] == stage[0][2] && stage[1][1] != '+' ) {
					cout << stage[1][1] << endl;
					break;
				}
			}
		}
		if( i == 3 ) cout << "NA" << endl;
	}

	return 0;
}

C++: #include<iostream>

using namespace std;
string s[3];
char judge(int i){
  int p = i*3;
  if(s[0][p] == s[1][p] && s[1][p] == s[2][p] && s[0][p] != '+'){
    return s[0][p];
  }
  if(s[0][p+1] == s[1][p+1] && s[1][p+1] == s[2][p+1] && s[0][p+1] != '+'){
    return s[0][p+1];
  }
  if(s[0][p+2] == s[1][p+2] && s[1][p+2] == s[2][p+2] && s[0][p+2] != '+'){
    return s[0][p+2];
  }
  if(s[0][p] == s[0][p+1] && s[0][p+1] == s[0][p+2] && s[0][p] != '+'){
    return s[0][p];
  }
  if(s[1][p] == s[1][p+1] && s[1][p+1] == s[1][p+2] && s[1][p] != '+'){
    return s[1][p];
  }
  if(s[2][p] == s[2][p+1] && s[2][p+1] == s[2][p+2] && s[2][p] != '+'){
    return s[2][p];
  }
  if(s[0][p] == s[1][p+1] && s[1][p+1] == s[2][p+2] && s[0][p] != '+'){
    return s[0][p];
  }
  if(s[0][p+2] == s[1][p+1] && s[1][p+1] == s[2][p] && s[0][p+2] != '+'){
    return s[0][p+2];
  }
  return 'd';
}

int main(){
  cin >> s[0];
  cin >> s[1];
  cin >> s[2];
  for(int i=0;i<s[0].length();i+=3){
    cout << judge(i/3) << endl;
  }
  return 0;
}

C++: //Name: Black-and-White
//Level: 1
//Category: 実装
//Note:

/**
 * 縦、横、斜めそれぞれについて、同じ文字が1列に並んでいるか、並んでいればどの文字かを判定する。
 */
#include <iostream>
#include <string>
#include <array>

using namespace std;

array<string,3> field;
char check_inner(int r, int c, int dr, int dc) {
    if(field[r][c] == field[r+dr][c+dc] && field[r][c] == field[r+dr*2][c+dc*2]) {
        return field[r][c];
    }
    return 0;
}

string check() {
    // Row
    for(int r = 0; r < 3; ++r) {
        char c = check_inner(r, 0, 0, 1);
        if(c != 0 && c != '+') return string()+c;
    }

    // Col
    for(int c = 0; c < 3; ++c) {
        char cc = check_inner(0, c, 1, 0);
        if(cc != 0 && cc != '+') return string()+cc;
    }

    // Diag
    {
        char c = check_inner(0, 0, 1, 1);
        if(c != 0 && c != '+') return string()+c;
    }
    {
        char c = check_inner(0, 2, 1, -1);
        if(c != 0 && c != '+') return string()+c;
    }
    return "NA";
}

bool solve() {
    for(int i = 0; i < 3; ++i) {
        cin >> field[i];
        if(field[i] == "0") return false;
    }

    cout << check() << endl;
    return true;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);

    while(solve()) ;
    return 0;
}

C++: #include<bits/stdc++.h>
using namespace std;
string s1, s2, s3;
int main() {
	while (cin >> s1, s1 != "0") {
		cin >> s2 >> s3;
		if (s1[0] != '+' && s1[0] == s1[1] && s1[1] == s1[2])cout << s1[0] << endl;
		else if (s2[0] != '+' && s2[0] == s2[1] && s2[1] == s2[2])cout << s2[0] << endl;
		else if (s3[0] != '+' && s3[0] == s3[1] && s3[1] == s3[2])cout << s3[0] << endl;
		else if (s1[0] != '+' && s1[0] == s2[0] && s2[0] == s3[0])cout << s1[0] << endl;
		else if (s1[1] != '+' && s1[1] == s2[1] && s2[1] == s3[1])cout << s1[1] << endl;
		else if (s1[2] != '+' && s1[2] == s2[2] && s2[2] == s3[2])cout << s1[2] << endl;
		else if (s1[0] != '+' && s1[0] == s2[1] && s2[1] == s3[2])cout << s1[0] << endl;
		else if (s1[2] != '+' && s1[2] == s2[1] && s2[1] == s3[0])cout << s1[2] << endl;
		else cout << "NA\n";
	}
}