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>
using namespace std;

int main() {
    vector<string> bd(3);
    while (cin >> bd[0], bd[0] != "0") {
        for (int i=1; i<3; ++i) cin >> bd[i];
        string res = "NA";
        for (int k=0; k<3; ++k) {
            if (bd[0][k] == bd[1][k] && bd[1][k] == bd[2][k]) res = bd[0][k];
            if (bd[k][0] == bd[k][1] && bd[k][1] == bd[k][2]) res = bd[k][0];
        }
        if (bd[0][0] == bd[1][1] && bd[1][1] == bd[2][2]) res = bd[0][0];
        if (bd[2][0] == bd[1][1] && bd[1][1] == bd[0][2]) res = bd[2][0];
        cout << res << 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])){
        flag=true;
        ans=v[i][0];
    }rep(i,3){
        if((v[0][i]==v[1][i])&&(v[1][i]==v[2][i])){
            flag=true;
            ans=v[0][i];
        }
    }if(v[0][0]==v[1][1]==v[2][2]){flag=true; ans=v[0][0];}
    if(v[0][2]==v[1][1]==v[2][0]){flag=true; ans=v[1][1];}
    if(flag)cout<<ans<<endl;
    else cout<<"NA"<<endl;
    }
}

C++: #include<iostream>
using namespace std;
int main()
{
  
  while(true)
    {
string str,str_x="";
 int count=0;
      for(int i=0;i<3;i++)
	{
      cin>>str;
      if(str=="0")return 0;
      str_x+=str;
	}
      for(int i=0;i<9;i+=3)
	{
	  if(str_x.at(i)=='b'&&str_x.at(i+1)=='b'&&str_x.at(i+2)=='b')
	    {
	      cout<<'b'<<endl;
 count++;
	    }
	  else if(str_x.at(i)=='w'&&str_x.at(i+1)=='w'&&str_x.at(i+2)=='w')
	    {
	      cout<<'w'<<endl;
 count++;
	    }
	}
  for(int i=0;i<3;i++)
    {
      if(str_x.at(i)=='b'&&str_x.at(i+3)=='b'&&str_x.at(i+6)=='b')
	{
	  cout<<'b'<<endl;
 count++;
	}
      else if(str_x.at(i)=='w'&&str_x.at(i+3)=='w'&&str_x.at(i+6)=='w')
	{
	  cout<<'w'<<endl;
 count++;
	}
    }
  if(str_x.at(0)=='b'&&str_x.at(4)=='b'&&str_x.at(8)=='b')
    {
cout<<'b'<<endl;
 count++;
    }
  else if(str_x.at(2)=='b'&&str_x.at(4)=='b'&&str_x.at(6)=='b')
    {
cout<<'b'<<endl;
 count++;
    }
  else if(str_x.at(0)=='w'&&str_x.at(4)=='w'&&str_x.at(8)=='w')
    {
      cout<<'w'<<endl;
 count++;
    }
  else if(str_x.at(2)=='w'&&str_x.at(4)=='w'&&str_x.at(6)=='w')
    {
      cout<<'w'<<endl;
 count++;
    }
  if(count==0)cout<<"NA"<<endl;
    }
  return 0;
}

C++: #include<iostream>
using namespace std;
int main()
{
  
  while(true)
    {
string str,str_x="";
 int count=0;
      for(int i=0;i<3;i++)
	{
      cin>>str;
      if(str=="0")return 0;
      str_x+=str;
	}
      for(int i=0;i<9;i+=3)
	{
	  if(str_x.at(i)=='b'&&str_x.at(i+1)=='b'&&str_x.at(i+2)=='b')
	    {
	      cout<<'b'<<endl;
 count++;
	    }
	  else if(str_x.at(i)=='w'&&str_x.at(i+1)=='w'&&str_x.at(i+2)=='w')
	    {
	      cout<<'w'<<endl;
 count++;
	    }
	}
  for(int i=0;i<3;i++)
    {
      if(str_x.at(i)=='b'&&str_x.at(i+3)=='b'&&str_x.at(i+6)=='b')
	{
	  cout<<'b'<<endl;
 count++;
	}
      else if(str_x.at(i)=='w'&&str_x.at(i+3)=='w'&&str_x.at(i+6)=='w')
	{
	  cout<<'w'<<endl;
 count++;
	}
    }
  if(str_x.at(0)=='b'&&str_x.at(4)=='b'&&str_x.at(8)=='b')
    {
cout<<'b'<<endl;
 count++;
    }
  else if(str_x.at(2)=='b'&&str_x.at(4)=='b'&&str_x.at(6)=='b')
    {
cout<<'b'<<endl;
 count++;
    }
  else if(str_x.at(0)=='w'&&str_x.at(4)=='w'&&str_x.at(8)=='w')
    {
      cout<<'w'<<endl;
 count++;
    }
  else if(str_x.at(2)=='w'&&str_x.at(4)=='w'&&str_x.at(6)=='w')
    {
      cout<<'w'<<endl;
 count++;
    }
  if(count==0)cout<<"NA"<<endl;
    }
}

C++: #include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>
using namespace std;
int main(){
    while(1){
        char ban[10][10] = {{0}};
        char field[10][10] = {{0}};
        cin >> field[0];
        if(field[0][0] == '0') break;
        cin >> field[1];
        cin >> field[2];
        for(int i = 0; i < 3; i++){
            for(int j = 0; j < 3; j++){
                ban[i+1][j+1] = field[i][j];
            }
        }
        for(int i = 1; i <= 3; i++){
            for(int j = 1; j <= 3; j++){
                if(i == 1){
                    int cnt = 0;
                    for(int l = 1; l <= 3; l++){
                        if(ban[i][j] == ban[l][j])cnt++;
                    }
                    if(cnt == 3){
                        printf("%c\n",ban[i][j]);
                        goto end;
                    }
                }
                if(j == 1){
                    int cnt = 0;
                    for(int l = 1; l <= 3; l++){
                        if(ban[i][j] == ban[i][l])cnt++;
                    }
                    if(cnt == 3){
                        printf("%c\n",ban[i][j]);
                        goto end;
                    }
                }
            }
        }
        printf("NA\n");
        end:;
    }
	return 0;
}

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

int mask[8]={0444,0222,0111,0700,070,07,0124,0421};
int create_mask(char c,char board[9]){
	int res=0;
	for(int i=0;i<9;i++){
		if(c==board[i])res |= 1<<i;
	}
	return res;
}
int main(){
	char board[9];
	int b,w;
	string win;
	while(cin>>board[0], board[0]!='0'){
		for(int i=1;i<9;i++)cin>>board[i];
		b = create_mask('b',board);
		w = create_mask('w',board);
		win = "NA";
		for(int i=0;i<8;i++){
			if((w&mask[i])==mask[i]){
				win="w";
				break;
			}
			else if((b&mask[i])==mask[i]){
				win="b";
				break;
			}
		}
		cout<<win<<endl;
	}
}