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

string s[9];
int dx[] = {0,0,1,-1,1,1-1,-1};
int dy[] = {1,-1,0,0,-1,1,-1,1};
int k;

bool solve(char c, int p, int y, int x){
  if(y < 0 || x < 0 || y == 3 || x == 3) return false;
  if(c != s[y][x] || c == '+') return false;
  if(p == 3) return true;
  solve(c, p+1, y+dy[k], x+dx[k]);
}

int main(){

  while(true){
    cin >> s[0];
    if(s[0] == "0") break;
    cin >> s[1] >> s[2];

    char c = '@';
    for(int i=0;i<3;i++){
      for(int j=0;j<3;j++){
	for(k=0;k<8;k++) if(solve(s[i][j], 1, i, j)) c = s[i][j];
      }
    }
    
    if(c == '@') cout << "NA" << endl;
    else cout << c << endl;
    
  }
}

C++: #include<iostream>
#include<cstdio>
using namespace std;
#define rep(i,n) for(i=0;i<n;i++)
int main() {
  while(1){
    int i;
    char a[5][5]={};
    bool ans=false;
    cin>>a[0];
    if(a[0][0]=='0')break;
    cin>>a[1];
    cin>>a[2];
    rep(i,3)
      if(a[i][0]==a[i][1] && a[i][1]==a[i][2] && a[i][0]!='+'){
        cout<<a[i][0]<<endl;
        ans=true;
        break;
      }else if(a[0][i]==a[1][i] && a[1][i]==a[2][i] && a[0][i]!='+'){
        cout<<a[0][i]<<endl;
        ans=true;
        break;
      }
    if(ans)continue;
    if((a[0][0]==a[1][1] && a[1][1]==a[2][2] && a[1][1]!='+')||
       (a[0][2]==a[1][1] && a[1][1]==a[2][0] && a[1][1]!='+'))
      cout<<a[1][1]<<endl;
    else
      cout<<"NA"<<endl;
  }
}

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

using namespace std;

int main(void){
	string str[3];
	while(cin >> str[0]){
		if(str[0] == "0") break;
		int r=-1;
		cin >> str[1] >> str[2];
		for(int i=0;i<3;i++){
			if(str[i][0] == str[i][1] && str[i][1] == str[i][2]){
				if(str[i][0] != '+'){
					str[i][0] == 'b'?r=0:r=1;
					break;
				}
			}
			if(str[0][i] == str[1][i] && str[1][i] == str[2][i]){
				if(str[0][i] != '+'){
					str[0][i] == 'b'?r=0:r=1;
					break;
				}
			}
		}
		if((str[0][0] == str[1][1] && str[1][1] == str[2][2]) ||
		(str[2][0] == str[1][1] && str[1][1] == str[0][2])){
			if(str[1][1] != '+'){
				str[1][1] == 'b'?r=0:r=1;
			}
		}
		if(r == -1){
			cout << "NA" << endl;
		}else{
			r==0?cout<<"b"<<endl:cout<<"w"<<endl;
		}
	}
}

C++: #include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

int main() {
  
  char grid[3][3];
  while(1) {
    for(int i=0; i<3; i++) {
      for(int j=0; j<3; j++) {
        cin >> grid[i][j];
        if(grid[i][j] == '0') return 0;
      }
    }
    
    for(int i=0; i<3; i++) {
      bool b = 1, w = 1;
      for(int j=0; j<3; j++) {
        if(grid[i][j] == 'b') w = 0;
        else if(grid[i][j] == 'w') b = 0;
        else b = 0, w = 0;
      }
      if(b) {
        cout << 'b' << endl;
        goto EXIT;
      }
      if(w) {
        cout << 'w' << endl;
        goto EXIT;
      }
    }
    
    for(int i=0; i<3; i++) {
      bool b = 1, w = 1;
      for(int j=0; j<3; j++) {
        if(grid[j][i] == 'b') w = 0;
        else if(grid[j][i] == 'w') b = 0;
        else b = 0, w = 0;
      }
      if(b) {
        cout << 'b' << endl;
        goto EXIT;
      }
      if(w) {
        cout << 'w' << endl;
        goto EXIT;
      }
    }
    
    bool b, w;
    
    b = 1, w = 1;
    for(int i=0; i<3; i++) {
      if(grid[i][i] == 'b') w = 0;
      else if(grid[i][i] == 'w') b = 0;
      else b = 0, w = 0;
    }
    if(b) {
      cout << 'b' << endl;
      goto EXIT;
    }
    if(w) {
      cout << 'w' << endl;
      goto EXIT;
    }
    
    b = 1, w = 1;
    for(int i=0; i<3; i++) {
      if(grid[i][2-i] == 'b') w = 0;
      else if(grid[i][2-i] == 'w') b = 0;
      else b = 0, w = 0;
    }
    if(b) {
      cout << 'b' << endl;
      goto EXIT;
    }
    if(w) {
      cout << 'w' << endl;
      goto EXIT;
    }
    
    cout << "NA" << endl;
    
  EXIT:;
  }
  
  return 0;
}