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 <cstdio>
using namespace std;
 
int main(){
 
  int i,j;
  char g[3][3];
  char win;
   
  while(1){
     
    for(i=0;i<3;i++){
      for(j=0;j<3;j++){
    cin >> g[i][j];
    if(g[0][0]=='0') return 0;
    if(g[i][j]=='+') g[i][j]=(j+1)*(i+1);
      }
    }
   
    for(i=0;i<3;i++){
      if(g[i][0]==g[i][1] && g[i][0]==g[i][2]){
    win = g[i][0];
    break;
      }else if(g[0][i]==g[1][i] && g[0][i]==g[2][i]){
    win = g[0][i];
    break;
      }else if(g[0][0]==g[1][1] && g[0][0]==g[2][2]){
    win = g[0][0];
    break;
      }else if(g[0][2]==g[1][1] && g[0][2]==g[2][0]){
    win = g[0][2];
    break;
      }
       
    }
     
    if(i!=3) printf("%c\n",win);
    else puts("NA");
 
  }
 
    return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for(int (i)=0; (i)<(int)(n); ++(i))
#define foreach(c,i) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)

string s[3];

string solve() {
  const char p[2] = { 'b', 'w' };
  string res = " ";
  rep (z,2) {
    const char c = p[z];
    bool ok = false;
    for (int i = 0; i < 3; ++i) {
      if (s[0][i] == c && s[1][i] == c && s[2][i] == c) ok = true;
      if (s[i][0] == c && s[i][1] == c && s[i][2] == c) ok = true;
    }
    if (s[0][0] == c && s[1][1] == c && s[2][2] == c) ok = true;
    if (s[0][2] == c && s[1][1] == c && s[2][0] == c) ok = true;
    if (ok) {
      res[0] = c; return res;
    }
  }
  return string("NA");
}

int main() {
  while (cin >> s[0]) {
    if (s[0][0] == '0') break;
    for (int i = 1; i < 3; ++i) cin >> s[i];
    cout << solve() << endl;
  }
  return 0;
}

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

int main(){

	int cnt_b, cnt_w;
	char c[3][3];
	
	while(cin >> c[0][0]){
		if(c[0][0] == '0') break;
		
		for(int i=0; i<3; i++){
			for(int j=0; j<3; j++){
				if(i != 0 || j != 0){
					cin >> c[i][j];
				}
			}
		}
		
	
		if(c[0][0] == c[1][1] && c[1][1] == c[2][2] ||
			 c[2][0] == c[1][1] && c[1][1] == c[0][2]){
			if(c[1][1] != '+') cout << c[1][1] << endl;
			else cout << "NA" << endl;
		}
		else {
			for(int i=0; i<3; i++){
				if(c[i][0] == c[i][1] && c[i][1] == c[i][2] || 
					 c[0][i] == c[1][i] && c[1][i] == c[2][i]){
					if(c[i][i] != '+'){
						cout << c[i][i] << endl;
						break;
					}
				}
				if(i == 2) cout << "NA" << endl;
			}
		}
		
	}

	return 0;

}

C++: #include<iostream>
#include<cmath>
#include<vector>
#include<string>
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]){
    if(maze[0][0] == '0')break;
    rep(i,3)rep(j,3){
      if(i==0&&j==0)continue;
      cin>>maze[i][j];
    }
    bool find = false;
    rep(i,3)if(maze[0][i] == maze[1][i] && 
	       maze[1][i] == maze[2][i] && 
	       maze[0][i] != '+'){
      cout<<maze[0][i]<<endl;
      find = true;
    }
    if(find)continue;
    rep(i,3)if(maze[i][0] == maze[i][1] && 
	       maze[i][1] == maze[i][2] && 
	       maze[i][2] != '+'){
      cout<<maze[i][1]<<endl;
      find = true;
    }
    if(find)continue;
    if(maze[0][0] == maze[1][1] && 
       maze[1][1] == maze[2][2] &&
       maze[1][1] != '+'){
      cout<<maze[0][0]<<endl;
      continue;
    }else if(maze[2][0] == maze[1][1] && 
	     maze[1][1] == maze[0][2] &&
	     maze[2][0] != '+'){
      cout<<maze[1][1]<<endl;
      continue;
    }else{
      cout<<"NA"<<endl;
    }
    
  }
  return 0;
}

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

using namespace std;

int main(){

	string str;
	while(cin>>str&&str!="0"){
		vector<string> field;
		field.push_back(str);
		for(int i = 0; i < 2; i++){
			cin>>str;
			field.push_back(str);
		}
		bool fin=false;
		// æ±
		for(int i = 0; i < 3; i++){
			bool f=false;
			char ch=field[i][0];
			if(ch!='+'){
				for(int j = 1; j < 3; j++){
					if(ch!=field[i][j]){
						f=true;
						break;
					}
				}
				// sè
				if(!f){
					cout<<ch<<endl;
					fin=true;
					break;
				}
			}
		}
		if(!fin){
			// ½Ä
			for(int i = 0; i < 3; i++){
				bool f=false;
				char ch=field[0][i];
				if(ch!='+'){
					for(int j = 1; j < 3; j++){
						if(ch!=field[j][i]){
							f=true;
							break;
						}
					}
					// sè
					if(!f){
						fin=true;
						cout<<ch<<endl;
						break;
					}
				}
			}
			if(!fin){
				// ÈÈß
				char ch=field[0][0];
				if(ch!='+'&&field[1][1]==ch&&field[2][2]==ch){
					fin=true;
					cout<<ch<<endl;
				}
				else if(field[1][1]!='+'&&field[1][1]==field[2][0]&&field[2][0]==field[0][2]){
					fin=true;
					cout<<ch<<endl;
				}
			}
			else
				cout<<"NA"<<endl;
		}
	}
	return 0;
}

C++: #include <iostream>

using namespace std;

void solve()
{

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

int main()
{
	solve();
	return(0);
}

C++: #include<cstdio>
#include<algorithm>
using namespace std;
int f(int a,int b,int c)
{
	if(a==b&&b==c&&a-'+')return a;
	return 0;
}
int main()
{
	char s[10];
	int i,c;
	while(c=0,scanf("%s",s),s[0]-'0')
	{
		scanf("%s%s",&s[3],&s[6]);
		for(i=0;i<3;++i)c=max(max(c,f(s[i*3],s[i*3+1],s[i*3+2])),f(s[i],s[i+3],s[i+6]));
		c=max(c,max(f(s[0],s[4],s[8]),f(s[2],s[4],s[6])));
		if(c)printf("%c\n",c);
		else puts("NA");
	}
	return 0;
}