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 <functional>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <iomanip>
#include <utility>
#include <cstdlib>
#include <sstream>
#include <bitset>
#include <vector>
#include <cstdio>
#include <ctime>
#include <queue>
#include <deque>
#include <cmath>
#include <stack>
#include <list>
#include <map>
#include <set>

using namespace std;

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

#define dump(x)  cerr << #x << " = " << (x) << endl
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back



int main() {
    char data[3][3];
    while(cin>>data[0][0]){
        if(data[0][0]=='0')break;
        rep(i,3){
            rep(j,3){
                if(i!=0 || j!=0){
                    cin>>data[i][j];
                }
            }
        }
        
        
        rep(i,3){
            if(data[i][0]==data[i][1] && data[i][1]==data[i][2]){
                cout<<data[i][0]<<endl;
                goto next;
            }
        }

        rep(j,3){
            if(data[0][j]==data[1][j] && data[1][j]==data[2][j]){
                cout<<data[0][j]<<endl;
                goto next;
            }
        }

        if( (data[0][0]==data[1][1] && data[1][1]==data[2][2]) || (data[0][2]==data[1][1] && data[1][1]==data[2][0]) ){
            cout<<data[1][1]<<endl;
            goto next;
        }
        
        
        cout<<"NA"<<endl;
        next:;
    }
    
    
    return 0;
}

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

int main()
{
	char field[3][3];
	while(true){
		for(int i=0;i<3;i++){
			for(int j=0;j<3;j++){
				cin >> field[i][j];
				if(field[i][j] == '0')
					return 0;
			}
		}
		bool flag = false;
		for(int i=0;i<3;i++){
			if(field[i][1] == field[i][0] && field[i][1] == field[i][2] && field[i][1] != '+'){
				cout << field[i][1] << endl;
				flag = true;
				break;
			}
			if(field[1][i] == field[0][i] && field[1][i] == field[2][i] && field[1][i] != '+'){
				cout << field[1][i] << endl;
				flag = true;
				break;
			}
		}
		if(flag)
			continue;
		if(((field[1][1] == field[0][0] && field[1][1] == field[2][2]) || (field[1][1] == field[2][0] && field[1][1] == field[0][2])) && field[1][1] != '+'){
			cout << field[1][1] << endl;
			continue;
		}
		cout << "NA" << endl;
	}
	return 0;
}

C++: #include<stdio.h>
char dat[3][4];
int main(){
	while(1){
		scanf("%s",dat[0]);
		if(dat[0][0]=='0')return 0;
		scanf("%s%s",dat[1],dat[2]);
		bool b=false;
		bool w=false;
		if(dat[0][0]=='w'&&dat[0][1]=='w'&&dat[0][2]=='w')w=true;
		if(dat[1][0]=='w'&&dat[1][1]=='w'&&dat[1][2]=='w')w=true;
		if(dat[2][0]=='w'&&dat[2][1]=='w'&&dat[2][2]=='w')w=true;
		if(dat[0][0]=='w'&&dat[1][0]=='w'&&dat[2][0]=='w')w=true;
		if(dat[0][1]=='w'&&dat[1][1]=='w'&&dat[2][1]=='w')w=true;
		if(dat[0][2]=='w'&&dat[1][2]=='w'&&dat[2][2]=='w')w=true;
		if(dat[0][0]=='w'&&dat[1][1]=='w'&&dat[2][2]=='w')w=true;
		if(dat[0][2]=='w'&&dat[1][1]=='w'&&dat[2][0]=='w')w=true;
		
		if(dat[0][0]=='b'&&dat[0][1]=='b'&&dat[0][2]=='b')b=true;
		if(dat[1][0]=='b'&&dat[1][1]=='b'&&dat[1][2]=='b')b=true;
		if(dat[2][0]=='b'&&dat[2][1]=='b'&&dat[2][2]=='b')b=true;
		if(dat[0][0]=='b'&&dat[1][0]=='b'&&dat[2][0]=='b')b=true;
		if(dat[0][1]=='b'&&dat[1][1]=='b'&&dat[2][1]=='b')b=true;
		if(dat[0][2]=='b'&&dat[1][2]=='b'&&dat[2][2]=='b')b=true;
		if(dat[0][0]=='b'&&dat[1][1]=='b'&&dat[2][2]=='b')b=true;
		if(dat[0][2]=='b'&&dat[1][1]=='b'&&dat[2][0]=='b')b=true;
		if(b)printf("b\n");
		else if(w)printf("w\n");
		else printf("NA\n");
	}
}

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

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

C++: #include <iostream>
#include <string>

using namespace std;

char solve(char board[9]) {
	//テァツクツヲ
	for (int i = 0; i < 3; i++)
		if (board[i] != '+' && board[i] == board[i + 3] && board[i] == board[i + 3 * 2]) 
			return board[i];

	//テヲツィツェ
	for (int i = 0; i < 9; i += 3)
		if (board[i] != '+' && board[i] == board[i + 1] && board[i] == board[i + 2])
			return board[i];

	//テヲツ鳴愿」ツつ?
	if (board[0] != '+' && board[0] == board[3 + 1] && board[0] == board[3 * 2 + 2])
		return board[0];
	if (board[2] != '+' && board[2] == board[3 + 1] && board[2] == board[3 * 2])
		return board[2];

	return 0;
}

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

	while (1) {
		char board[9];
		cin >> board[0];
		if (board[0] == '0') break;
		for (int i = 1; i < 9; i++)
			cin >> board[i];
		char c;
		if ((c = solve(board)))
			cout << c << endl;
		else
			cout << "NA" << endl;
	}
}

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, n_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");
				n_flag = true;
			}
			else if (y_comp == set[1] || t_comp == set[1]) {
				printf("w\n");
				n_flag = true;
			}
			y_comp.clear();
			t_comp.clear();
			
			r_comp += board[i][i];
		}
		if (r_comp == set[0] || l_comp == set[0]) {
			printf("b\n");
			n_flag = true;
		}
		else if (r_comp == set[1] || l_comp == set[1]) {
			printf("w\n");
			n_flag = true;
		}
		r_comp.clear();
		l_comp.clear();
		if (!n_flag) puts("NA");
	}
	
	return (0);
}