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++: //AOJ 0183
#include <iostream>
#include <string>
using namespace std;
int main(){
	string s[3];
	char w;
	while (1) {
		for (auto& i : s) {
			cin>>i;
			if(i == "0") return 0;
		}
		bool end = false;
		for (int i = 0; i < 3; i++) {
			char c = s[i][0];
			bool flag = true;
			for (int j = 0; j < 3; j++)
				if(s[i][j] != c) {flag = false;break;}
			if(flag && s[i][0] != '+') putchar(c),putchar('\n'),end = true;
		}
		if(end) goto fin;
		for (int i = 0; i < 3; i++) {
			char c = s[0][i];
			bool flag = true;
			for (int j = 0; j < 3; j++)
				if(s[j][i] != c) {flag = false;break;}
			if(flag && s[0][i] != '+') putchar(c),putchar('\n'),end = true;
		}
		if(end) goto fin;
		w = s[0][0];
		end = true;
		for (int i = 0; i < 3; i++)
			if(s[i][i] != w){end = false;break;}
		if(end && w != '+') putchar(w),putchar('\n');
		if(end) goto fin;
		w = s[0][2];
		end = true;
		for (int i = 0; i < 3; i++) {
			if(s[i][2-i] != w) {end = false;break;}
		}
		if(end && w != '+') putchar(w),putchar('\n');
fin:
		if(!end) puts("NA");
	}
	return 0;
}

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

int main(){
	char b[3][3];
	int x,y;
	int check;
	int boolean = 1;

	while(boolean){
		x = 0;
		y = 0;
		check = 1;
		for(int i = 0; i < 3; i++){
			cin >> b[i];
			if(b[0][0] == '0'){
				 boolean = 0;
				 check = 0;
				 break;
			}
		}
		for(int i = 0; i <= 2; i++){
			if(b[i][0] == 'b' && b[i][1] == 'b' && b[i][2] == 'b'){
		cout << 'b' << endl;
		check = 0; break;
			}
			if(b[0][i] == 'b' && b[1][i] == 'b' && b[2][i] == 'b'){
		cout << 'b' << endl;
		check = 0; break;
			}
			if(b[0][0] == 'b' && b[1][1] == 'b' && b[2][2] == 'b'){
		cout << 'b' << endl;
		check = 0; break;
			}
			if(b[2][0] == 'b' && b[1][1] == 'b' && b[2][0] == 'b'){
		cout << 'b' << endl;
		check = 0; break;
			}

		}
		for(int i = 0; i <= 2; i++){
			if(b[i][0] == 'w' && b[i][1] == 'w' && b[i][2] == 'w'){
		cout << 'w' << endl;
		check = 0; break;
			}
			if(b[0][i] == 'w' && b[1][i] == 'w' && b[2][i] == 'w'){
		cout << 'w' << endl;
		check = 0; break;
			}
			if(b[0][0] == 'w' && b[1][1] == 'w' && b[2][2] == 'w'){
		cout << 'w' << endl;
		check = 0; break;
			}
			if(b[2][0] == 'b' && b[1][1] == 'b' && b[2][0] == 'b'){
		cout << 'w' << endl;
		check = 0; break;
			}

		}
		if(check) cout << "NA" << endl;
	}
}

C++: #include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cctype>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<stack>
#include<queue>
#include<map>

using namespace std;
const int dx[] = {1,0,-1,0},dy[] = {0,1,0,-1};
#define INF 999999
#define rep(i,j) for(int i=0;i<(j);i++)
#define reps(i,j,k) for(int i=j;i<k;i++)
typedef long long ll;
typedef unsigned long long ull;
int main(){
    char stage[4][4]={{0}};
    while(scanf("%s",stage[0]), stage[0][0] != '0'){
        reps(i,1,3)scanf("%s",stage[i]);
        /*Check*/
        bool f = false;
        rep(i,3){
            if(stage[i][0] == 'b' && stage[i][1] == 'b' && stage[i][2] == 'b'){
                puts("b");
                f = true;
            }
            if(stage[i][0] == 'w' && stage[i][1] == 'w' && stage[i][2] == 'w'){
                puts("w");
                f = true;
            }
            if(stage[0][i] == 'b' && stage[1][i] == 'b' && stage[2][i] =='b'){
                puts("b");
                f = true;
            }
            if(stage[0][i] == 'w' && stage[1][i] =='w' && stage[2][i] == 'w'){
                puts("w");
                f = true;
            }
        }
        if(stage[0][0] == stage[1][1] && stage[1][1] ==stage[2][2] &&stage[0][0] == 'b'){
            puts("b");
            f = true;
        }
        if(stage[0][0] == stage[1][1] && stage[1][1] ==stage[2][2] &&stage[0][0] == 'w'){
            puts("w");
            f = true;
        }
        if(stage[0][2] == stage[1][1] && stage[1][1] ==stage[2][0] &&stage[0][2] == 'b'){
            puts("b");
            f = true;
        }
        if(stage[0][2] == stage[1][1] && stage[1][1] ==stage[2][0] &&stage[0][2] == 'w'){
            puts("w");
            f = true;
        }
        if(!f)puts("NA");
    }
    return 0;
}

C++: #include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  char in[3][4];
  while(cin>>in[0],in[0][0]!='0'){
    rep(i,2)cin>>in[i+1];
    bool h=false;
    rep(i,3){
      if(in[0][i]==in[1][i]&&in[1][i]==in[2][i]&&in[0][i]!='+'){cout<<in[0][i]<<endl;h=true;break;}
      else if(in[i][0]==in[i][1]&&in[i][1]==in[i][2]&&in[i][0]!='+'){cout<<in[i][0]<<endl;h=true;break;}
    }
    if(!h){
      if(in[0][0]==in[1][1]&&in[1][1]==in[2][2]&&in[0][0]!='+')cout<<in[0][0]<<endl;
      else if(in[2][0]==in[1][1]&&in[1][1]==in[0][2]&&in[1][1]!='+')cout<<in[1][1]<<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[2][0] == stage[1][1] && stage[1][1] == stage[0][2] ) {
					cout << stage[0][0] << endl;
					break;
				}
			}
		}
		if( i == 3 ) cout << "NA" << endl;
	}

	return 0;
}