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<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[1][i] && 
	       maze[i][1] == maze[2][i] && 
	       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<bits/stdc++.h>
using namespace std;
typedef long long int lld;

int main(){
  string str[3];
  string dif[] = {"bbb","www"};
  while(cin >> str[0] , str[0] != "0"){
    cin >> str[1];
    cin >> str[2];
    bool flg = false;;
    for(int i=0;i<3;i++){
      for(int j=0;j<2;j++){
	if(str[i] == dif[j]){
	  cout << str[i][0] << endl;
	  flg = true;
	  break;
	}
      }
      if(flg) break;
    }
    if(!flg){
      for(int i=0;i<3;i++){
	string tmp = "";
	for(int j=0;j<3;j++) tmp += str[j][i];
	for(int j=0;j<2;j++){
	  if(tmp == dif[j]){
	    cout << tmp[0] << endl;
	    flg = true;
	    break;	  
	  }
	}
	if(flg) break;
      }
    }
    if(!flg){
      string tmp = "";
      for(int i=0;i<3;i++) tmp += str[i][i];
      for(int i=0;i<2;i++){
	if(tmp == dif[i]){
	  cout << tmp[0] << endl;
	  flg = true;
	  break;	  
	}
      }
      if(!flg){
	string tmp = "";
	for(int i=0;i<3;i++) tmp += str[2-i][i];
	for(int i=0;i<2;i++){
	  if(tmp == dif[i]){
	    cout << tmp[0] << endl;
	    flg = true;
	    break;	  
	  }
	}
      }
    }
    if(!flg) cout << "NA" << endl;
  }			     
}

C++: #define _USE_MATH_DEFINES
#include <iostream>
#include <complex>
#include <algorithm>
#include <vector>
#include <stack>
#include <string>
#include <queue>
#include <cmath>
#include <math.h>
#include <numeric>
#include <list>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <climits>
#include <set>
#include <memory.h>
#include <memory>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cassert>
#include <map>
#include <cassert>
#include <time.h>
#include <ctime>

using namespace std;

typedef complex<double> xy_t;
typedef pair<xy_t, xy_t> line;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<int , P> PP;
typedef pair<int, string> Ps;
typedef vector<int> vec;
typedef vector<vec> mat;
const int INF = 1 << 30;
const double EPS = 1e-9;
const double PI = 3.1415926535897932384626433832795;
const int CLK = CLOCKS_PER_SEC;

#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, m, n) for(int i = m; i < n; i++)

char field[9];

bool ok(char c){
	bool res = false;
	bool f;
	rep(i, 3){
		f = true;
		rep(j, 3) if(field[i*3+j]!=c) f = false;
		if(f) res = true;
	}
	rep(i, 3){
		f = true;
		rep(j, 3) if(field[i+j*3]!=c) f = false;
		if(f) res = true;
	}
	if(field[0] == c && field[4] == c && field[8] == c) res = true;
	if(field[2] == c && field[4] == c && field[6] == c) res = true;
	return res;

}

int main(){
	while(cin >> field[0] && field[0] != '0'){
		rep2(i, 1, 9) cin >> field[i];
		bool b = ok('b');
		bool w = ok('w');
		if(b) cout << 'b' << endl;
		else if(w) cout << 'w' << endl;
		else cout << "NA" << endl;
	}
	return 0;
}

C++: #include<stdio.h>
#include<iostream>
#include<string>
#include<algorithm>
#include <vector>
#include<math.h>


using namespace std;

int main(){




	string p,q,r;
	while(1){
		cin>>p;if(p=="0")break;
		cin>>q>>r;
	char ch[4][4]={};

	for(int i=0;i<3;i++)
	{
		ch[0][i]=p[i];
		ch[1][i]=q[i];
		ch[2][i]=r[i];
	}
	char win='N';

	for(int i=0;i<3;i++)
	{
		if(ch[i][0]==ch[i][1]&&ch[i][0]==ch[i][2]&&ch[i][0]!='+'){
			win=ch[i][0];
		}
		
		if(ch[0][i]==ch[1][i]&&ch[0][i]==ch[2][i]&&ch[0][i]!='+'){
			win=ch[0][i];
		}
	}
	if(ch[0][0]==ch[1][1]&&ch[0][0]==ch[2][2]&&ch[0][0]!='+'){
			win=ch[0][0];
		}
	if(ch[0][2]==ch[1][1]&&ch[0][2]==ch[2][0]&&ch[0][2]!='+'){
			win=ch[0][2];
		}

if(win!='N')cout<<win<<endl;
else cout<<"NA"<<endl;
	}

	return 0;
}

C++: #include<iostream>
#include<iomanip>
#include<algorithm>
#include<array>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<unordered_map>
#include<queue>
#include<vector>
using namespace std;

//#define int long long
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define dump(o) {cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) {cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL
const int MOD = 1e9 + 7;

signed main() {
	string s[3];
	for (; cin >> s[0]&&s[0] != "0";) {
		cin >> s[1] >> s[2];
		bool b, w;
		b = w = false;
		rep(i, 0, 3) {
			if (s[i][0] == s[i][1] && s[i][1] == s[i][2]) {
				if (s[i][0] == 'b')b = true;
				if (s[i][0] == 'w')w = true;
			}
		}
		rep(j, 0, 3) {
			if (s[0][j] == s[1][j] && s[1][j] == s[2][j]) {
				if (s[0][j] == 'b')b = true;
				if (s[0][j] == 'w')w = true;
			}
		}

		if (s[0][0] == s[1][1] && s[1][1] == s[2][2]) {
			if (s[0][0] == 'b')b = true;
			if (s[0][0] == 'w')w = true;
		}

		if (s[0][2] == s[1][1] && s[1][1] == s[2][0]) {
			if (s[0][2] == 'b')b = true;
			if (s[0][2] == 'w')w = true;
		}
		if (b)cout << "b" << endl;
		else if (w)cout << "w" << endl;
		else cout << "NA" << endl;
	}
	return 0;
}