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<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[1][1]==v[2][2])){flag=true; ans=v[0][0];}
    if((v[0][2]==v[1][1])&&(v[1][1]==v[2][0])){flag=true; ans=v[1][1];}
    if(flag&&ans!='+')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))
	    {
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>
using namespace std;

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

    return 0;
}

C++: 
#include<iostream>
using namespace std;
int main()
{
  int i;
  string s[3],ans;
  while(cin>>s[0]>>s[1]>>s[2],s[0]!="0"){
    ans="NA";
    for(i=0;i<3;i++){
      if(s[i][0]!='+' && s[i][0]==s[i][1] && s[i][0]==s[i][2])ans=s[i][0];
      if(s[0][i]!='+' && s[0][i]==s[1][i] && s[0][i]==s[2][i])ans=s[0][i];
    }
    if(s[1][1]!='+' && s[1][1]==s[1][1] && s[1][1]==s[2][2])ans=s[1][1];
    if(s[1][1]!='+' && s[1][1]==s[0][2] && s[1][1]==s[2][0])ans=s[1][1];

    cout<<ans<<endl;
  }
}

C++: #include<iostream>
#include<cmath>
#include<vector>
#include<string>
#include<map>
#include<set>
#include<algorithm>
#include<cstdio>
typedef unsigned long long ull;
#define rep(i,a) for(int i=0;i<a;i++)
#define loop(i,a,b) for(int i=a;i<b;i++)
using namespace std;
const double eps = 1e-10;
const double pi = acos(-1);
const double inf = (int)1e8;

int main(void){
  char maze[3][3];
  while(cin>>maze[0][0],maze[0][0] != '0'){
    rep(i,3)rep(j,3){
      if(i==0&&j==0)continue;
      cin>>maze[i][j];
    }
    bool find = false;
    rep(i,3){
      if(maze[i][0] == maze[i][1] &&maze[i][1] == maze[i][2]){
	cout<<maze[i][0]<<endl;
	find = true;
	break;
      }
    }
    if(find)continue;
    rep(i,3){
      if(maze[0][i] == maze[1][i] &&maze[1][i] == maze[2][i]){
	cout<<maze[0][i]<<endl;
	find = true;
	break;
      }
    }
    if(find)continue;
    if(maze[0][0] == maze[1][1] && maze[1][1] == maze[2][2]){
      cout<<maze[1][1]<<endl;
      continue;
    }
    if(maze[0][2] == maze[1][1] && maze[1][1] == maze[2][0]){
      cout<<maze[1][1]<<endl;
      continue;
    }
    cout<<"NA"<<endl;
  }
  
  
  return 0;
}