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 <algorithm>
#include <cctype>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <vector>

using namespace std;

#define reps(i,f,n) for(int i=f; i<int(n); ++i)
#define rep(i,n) reps(i,0,n)

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main()
{
	for(;;){
		char str[3][8];
		rep(i, 3){
			scanf("%s", str[i]);
			if(str[i][0] == '0')
				return 0;
		}
		
		const int sy[] = {0, 1, 2, 0, 0, 0, 0, 0};
		const int sx[] = {0, 0, 0, 0, 1, 2, 0, 2};
		const int dy[] = {0, 0, 0, 1, 1, 1, 1, 1};
		const int dx[] = {1, 1, 1, 0, 0, 0, 1,-1};
		int winner = 0;
		rep(i, 8){
			int y = sy[i], x = sx[i];
			int b = 0, w = 0;
			rep(j, 3){
				b += str[y][x] == 'b';
				w += str[y][x] == 'w';
				y += dy[i];
				x += dx[i];
			}
			if(b == 3){
				winner = 1;
				break;
			}
			if(w == 3){
				winner = 2;
				break;
			}
		}
		
		if(winner == 0)
			puts("NA");
		else
			puts(winner == 1 ? "b" : "w");
	}
}

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

string solve( vector< string >& map )
{
	char row, col, rd, ld, comp;
	rd = map[ 0 ][ 0 ];
	ld = map[ 0 ][ 2 ];
	for( int i = 0; i < 3; ++i ){
		row = map[ 0 ][ i ];
		col = map[ i ][ 0 ];
		for( int j = 0; j < 3; ++j ){
			if( row != map[ j ][ i ] ){
				row = 0;
			}
			if( col != map[ i ][ j ] ){
				col = 0;
			}
		}
		comp = row | col;
		if( comp && comp != '+' ){
			return string( 1, row | col );
		}
		if( rd != map[ i ][ i ] ){
			rd = 0;
		}
		if( ld != map[ i ][ 2 - i ] ){
			ld = 0;
		}
	}

	comp = rd | ld;

	return ( comp && comp != '+' ) ? string( 1, comp ) : "NA";
}

int main()
{
	string s;
	while( cin >> s && s != "0" ){
		vector< string > map;
		map.push_back( s );
		for( int i = 0; i < 2; ++i ){
			cin >> s;
			map.push_back( s );
		}
		cout << solve( map ) << endl;
	}

	return 0;
}

C++: #include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b) - 1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

#define PB push_back
#define INF INT_MAX/3
#define ALL(a) (a).begin(),(a).end()
#define CLR(a) memset(a,0,sizeof(a))

typedef long long int ll;

using namespace std;

int main(){
    while(true){
	string s[3];
	bool flg = false;
	cin >> s[0];
	if(s[0] == "0") break;
	cin >> s[1] >> s[2];
	REP(i,3)
	    if(s[i][0] == s[i][1] && s[i][0] == s[i][2]){
		cout << s[i][0] << endl;
		flg = true;
	    }
	if(flg) continue;
	REP(i,3)
	    if(s[0][i] == s[1][i] && s[0][i] == s[2][i]){
		cout << s[0][i] << endl;
		flg = true;
	    }
	if(flg) continue;

	if(s[0][0] == s[1][1] && s[0][0] == s[2][2]){
	    cout << s[0][0] << endl;
	    flg = true;
	}
	if(flg) continue;
	if(s[0][2] == s[1][1] && s[2][0] == s[1][1]){
	    cout << s[0][2] << endl;
	    flg = true;
	}
	if(flg) continue;
	cout << "NA" << endl;
    }
    return 0;
}

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

char field[3][4];

char solve(){
	for(int i=0; i<3; i++){
		if(field[i][0] == field[i][1] && field[i][1] == field[i][2] && (field[i][0] == 'w' || field[i][0] == 'b'))
			return field[i][0];
	}
	for(int k=0; k<3; k++){
		if(field[0][k] == field[1][k] && field[1][k] == field[2][k] && (field[0][k] == 'w' || field[0][k] == 'b'))
			return field[0][k];
	}
	if(field[0][0] == field[1][1] && field[1][1] == field[2][2] && (field[0][0] == 'w' || field[0][0] == 'b'))
		return field[0][0];
	if(field[0][2] == field[1][1] && field[1][1] == field[2][0] && (field[0][2] == 'w' || field[0][2] == 'b'))
		return field[0][2];
	return 'N';
}

int main(){
	while(true){
		for(int i=0; i<3; i++){
			cin >> field[i];
			if(field[0][0] == '0')
				return 0;
		}
		char ans = solve();
		if(ans != 'N')
			cout << "NA\n";
		else
			cout << ans << endl;
	}
}

C++: #include <iostream>
#include <string>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
char same(char c[3][3]) {
	char ret = '+';
	rep(i,3) {
		if(c[i][0] == c[i][1] && c[i][1] == c[i][2] && c[i][0] != '+') ret = c[i][0];
	}
	rep(i,3) {
		if(c[0][i] == c[1][i] && c[1][i] == c[2][i] && c[0][i] != '+') ret = c[0][i];
	}
	if(c[0][0] == c[1][1] && c[1][1] == c[2][2] && c[0][0] != '+') ret = c[0][0];
	if(c[2][0] == c[1][1] && c[1][1] == c[0][2] && c[2][0] != '+') ret = c[2][0];
	return ret;
}
int main(){
	char b[3][3];
	string s;
	while(cin >> s, s != "0") {
		rep(i,3) {
			b[0][i] = s[i];
		}
		rep2(i,1,3) {
			cin >> s;
			rep(j,3) {
				b[i][j]= s[j];
			}
		}
		if(same(b) == '+') cout << "NA" << endl;
		else cout << same(b) << endl;
	}
	return 0;
}

C++: #include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define CC puts("-------ok--------");
#define all(in) in.begin(), in.end()
#define bv vector<bool>
using namespace std;
typedef pair<int, int> pii;
#define MAX 99999999
int main(){
    vector<vector<char>>v(5,vc(5));
    while(cin>>v[0][0]){
        if(v[0][0]=='0')break;
        else for(int i=0; i<3;i++)
            for(int j=0; j<3;j++){
                if((i==0&&j==0))continue;
                    cin>>v[i][j];
            }
    bool flag=false; char ans = '\0';
    rep(i,3)if((v[i][0]==v[i][1])&&(v[i][1]==v[i][2])&&v[i][0]!='+'){
        flag=true;
        ans=v[i][0];
    }rep(i,3){
        if((v[0][i]==v[1][i])&&(v[1][i]==v[2][i])&&v[0][i]!='+'){
            flag=true;
            ans=v[0][i];
        }
    }if((v[0][0]==v[1][1])&&(v[1][1]==v[2][2])&&v[0][0]!='+'){flag=true; ans=v[0][0];}
    if((v[0][2]==v[1][1])&&(v[1][1]==v[2][0])&&v[1][1]!='+'){flag=true; ans=v[1][1];}
    if(flag)cout<<ans<<endl;
    else cout<<"NA"<<endl;
    }
}