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 "bits/stdc++.h"

using namespace std;

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

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

char solve(string data[3]){
	rep(i,3){
		if( data[i][0]==data[i][1] && data[i][1]==data[i][2] && data[i][0]!='+' ){
			return data[i][0];
		}
	}
	rep(i,3){
		if( data[0][i]==data[1][i] && data[1][i]==data[2][i] && data[0][i]!='+' ){
			return data[0][i];
		}
	}
	if( data[0][0]==data[1][1] && data[1][1]==data[2][2] && data[0][0]!='+' )return data[1][1];
	if( data[0][2]==data[1][1] && data[1][1]==data[2][0] && data[0][0]!='+' )return data[1][1];


	return '+';
}


int main(){
	string s;
	while(cin>>s){
		string data[3];
		if(s=="0")break;
		data[0]=s;
		rep(i,2)cin>>data[i+1];

		char res = solve(data);
		if(res=='+')cout<<"NA"<<endl;
		else cout<<res<<endl;
	}
}

C++: #include<iostream>
#include<string>
using namespace std;
int main(){
  string b[3];
  while(1){
    cin>>b[0];
    if(b[0]=="0")
      break;
    cin>>b[1];
    cin>>b[2];
    int flag=0;
    for(int i=0;i<3;i++){
      if(b[0].at(i)==b[1].at(i)&&b[2].at(i)==b[1].at(i)&&b[0].at(i)=='b') flag=1;
      if(b[0].at(i)==b[1].at(i)&&b[2].at(i)==b[1].at(i)&&b[0].at(i)=='w') flag=-1;
      if(b[i].at(0)==b[i].at(1)&&b[i].at(1)==b[i].at(2)&&b[i].at(0)=='b') flag=1;
      if(b[i].at(0)==b[i].at(1)&&b[i].at(1)==b[i].at(2)&&b[i].at(0)=='w') flag=-1;
    }
      if(b[0].at(0)==b[1].at(1)&&b[1].at(1)==b[2].at(2)&&b[0].at(0)=='w') flag=-1;
      if(b[0].at(2)==b[1].at(1)&&b[1].at(1)==b[2].at(0)&&b[0].at(0)=='w') flag=-1;
      if(b[0].at(0)==b[1].at(1)&&b[1].at(1)==b[2].at(2)&&b[0].at(0)=='b') flag=1;
      if(b[0].at(2)==b[1].at(1)&&b[1].at(1)==b[2].at(0)&&b[0].at(0)=='b') flag=1;

      if(flag==1) cout<<"b"<<endl;
      else if(flag==-1) cout<<"w"<<endl;
      else cout<<"NA"<<endl;
  }
}

C++: #include<iostream>
using namespace std;
int main(void){
    for(;;){
    char a[3][3];
    int f=0,z=0;
    for (int i=0;i<3;i++){
        cin>>a[i];
        if(a[i][0]=='0'){
            z++;
            break;
        }
        }
        if(z!=0)break;

    for(int i=0;i<1;i++){
        for(int j=0;j<3;j++){
            if(a[i][j]!='+'){
                if(a[0][j]==a[1][j]&&a[1][j]==a[2][j]){
                    cout<<a[0][j]<<endl;
                    f++;
                    goto c;
                }
            }
        }
    }
    for(int j=0;j<1;j++){
        for(int i=0;i<3;i++){
            if(a[i][j]!='+'){
                if(a[0][j]==a[1][j]&&a[1][j]==a[2][j]){
                    cout<<a[0][j]<<endl;
                    f++;
                    goto c;
                }
            }
        }
    }
    if(a[0][0]!='+'){
        if(a[0][0]==a[1][1]&&a[1][1]==a[2][2]){
            cout<<a[0][0]<<endl;
            f++;
            goto c;
        }

    }
    if(a[0][2]!='+'){
        if(a[0][2]==a[1][1]&&a[1][1]==a[2][0]){
            cout<<a[0][0]<<endl;
            f++;
            goto c;
        }
    }

    if(f==0)cout<<"NA"<<endl;
    c:;


    }
    return 0;
}

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

char mat[3][3];

char judge(){
    for(int i = 0; i < 3; i++){
        if(mat[i][0] == mat[i][1] && mat[i][1] == mat[i][2]) return mat[i][2];
        if(mat[0][i] == mat[1][i] && mat[1][i] == mat[2][i]) return mat[2][i];
    }
    if(mat[0][0] == mat[1][1] && mat[1][1] == mat[2][2])    return mat[1][1];
    if(mat[0][2] == mat[1][1] && mat[1][1] == mat[2][0])    return mat[1][1];

    return '?';
}


int main(){
    while(1){
        cin >> mat[0][0];
        if(mat[0][0] == '0')    break;
        cin >> mat[0][1] >> mat[0][2];
        for(int i = 1; i < 3; i++){
            for(int j = 0; j < 3; j++){
                cin >> mat[i][j];
            }
        }
        char res = judge();
        if(res == '?')  cout << "NA" << endl;
        else            cout << res << 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])
			return field[i][0];
	}
	for(int k=0; k<3; k++){
		if(field[0][k] == field[1][k] && field[1][k] == field[2][k])
			return field[0][k];
	}
	if(field[0][0] == field[1][1] && field[1][1] == field[2][2])
		return field[0][0];
	if(field[0][2] == field[1][1] && field[1][1] == field[2][0])
		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;
int main(){
  string b[3],s;
  while(1){
    cin>>b[0];
    s="";
    if(b[0]=="0")
      break;
    cin>>b[1];
    cin>>b[2];
    int flag=0;
    for(int i=0;i<3;i++){
      if(b[0].at(i)==b[1].at(i)&&b[2].at(i)==b[1].at(i)) s=b[0].at(i);
      if(b[i].at(0)==b[i].at(1)&&b[i].at(1)==b[i].at(2)) s=b[i].at(0);
    }
    if(b[0].at(0)==b[1].at(1)&&b[1].at(1)==b[2].at(2)) s=b[0].at(0);
    if(b[0].at(2)==b[1].at(1)&&b[1].at(1)==b[2].at(0)) s=b[0].at(2);

    if(s=="b"||s=="w") cout<<s<<endl;
    else cout<<"NA"<<endl;
  }
}

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

char b[3][3];

bool check(char c) {
	for (int i = 0; i < 3; i++) {
		if (b[i][0] == c && b[i][1] == c && b[i][2] == c) return true;
		if (b[0][i] == c && b[1][i] == c && b[2][i] == c) return true;
	}
	if (b[0][0] == c && b[1][1] == c && b[2][2] == c) return true;
	if (b[0][2] == c && b[1][1] == c && b[2][0] == c) return true;
	return false;
}

int main() {
	while (true) {
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				cin >> b[i][j];
				if (b[i][j] == '0') return 0;
			}
		}

		if (check('b')) {
			cout << 'b' << endl;
		}
		else if (check('w')) {
			cout << 'w' << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
}