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 <bits/stdc++.h>
using namespace std;

int main()
{
  string str1, str2, str3;
  while (cin >> str1, str1 != "0"){
    bool b, w;
    b = w = false;
    cin >> str2 >> str3;

    if (str1[0] == str1[1] && str1[1] == str1[2]){
      if (str1[0] == 'b') b = true;
      if (str1[0] == 'w') w = true;
    }
    else if (str2[0] == str2[1] && str2[1] == str2[2]){
      if (str2[0] == 'b') b = true;
      if (str2[0] == 'w') w = true;
    }
    else if (str3[0] == str3[1] && str3[1] == str3[2]){
      if (str3[0] == 'b') b = true;
      if (str3[0] == 'w') w = true;
    }
    else if (str1[0] == str2[0] && str2[0] == str3[0]){
      if (str1[0] == 'b') b = true;
      if (str1[0] == 'w') w = true;
    }
    else if (str1[1] == str2[1] && str2[1] == str3[1]){
      if (str1[1] == 'b') b = true;
      if (str1[1] == 'w') w = true;
    }
    else if (str1[2] == str2[2] && str2[2] == str3[2]){
      if (str1[2] == 'b') b = true;
      if (str1[2] == 'w') w = true;
    }
    else if (str1[0] == str2[1] && str2[1] == str3[2]){
      if (str1[0] == 'b') b = true;
      if (str1[0] == 'w') w = true;
    }
    else if (str1[2] == str2[1] && str2[1] == str3[0]){
      if (str1[2] == 'b') b = true;
      if (str1[2] == 'w') w = true;
    }

    if (b)  cout << 'b';
    if (w) cout << 'w';
    if (!b && !w)cout << "NA";
    cout << endl;
  }
}

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

int main(void){
	string str[3];
	while(1){
		cin >> str[0];
		if(str[0]=="0")break;
		cin >> str[1];
		cin >> str[2];
		if(str[0]=="bbb" || str[1]=="bbb" || str[2]=="bbb")cout << "b" << endl;
		else if(str[0][0]=='b' && str[1][0]=='b' && str[2][0]=='b')cout << "b" << endl;
		else if(str[0][1]=='b' && str[1][1]=='b' && str[2][1]=='b')cout << "b" << endl;
		else if(str[0][2]=='b' && str[1][2]=='b' && str[2][2]=='b')cout << "b" << endl;
		else if(str[0][0]=='b' && str[1][1]=='b' && str[2][2]=='b')cout << "b" << endl;
		else if(str[0][2]=='b' && str[1][1]=='b' && str[2][0]=='b')cout << "b" << endl;
		else if(str[0]=="www" || str[1]=="www" || str[2]=="www")cout << "w" << endl;
		else if(str[0][0]=='w' && str[1][0]=='w' && str[2][0]=='w')cout << "w" << endl;
		else if(str[0][1]=='w' && str[1][1]=='w' && str[2][1]=='w')cout << "w" << endl;
		else if(str[0][2]=='w' && str[1][2]=='w' && str[2][2]=='w')cout << "w" << endl;
		else if(str[0][0]=='w' && str[1][1]=='w' && str[2][2]=='w')cout << "w" << endl;
		else if(str[0][2]=='w' && str[1][1]=='w' && str[2][0]=='w')cout << "w" << endl;
		else cout << "NA" << endl;
	}
    return 0;
}

C++: #define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;

//#define int long long
#define DBG 1
#define dump(o) if(DBG){cerr<<#o<<" "<<o<<endl;}
#define dumpc(o) if(DBG){cerr<<#o; for(auto &e:(o))cerr<<" "<<e;cerr<<endl;}
#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 each(it,c) for(auto it=(c).begin();it!=(c).end();it++)
#define all(c) c.begin(),c.end()
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9 + 7);
const double EPS = 1e-10;
bool check(vector<string>v, char x) {
	rep(i, 0, 3)if (v[i][0] == x&&v[i][1] == x&&v[i][2] == x || v[0][i] == x&&v[1][i] == x&&v[2][i] == x)return true;
	if (v[0][0] == x&&v[1][1] == x&&v[2][2] == x || v[0][2] == x&&v[1][1] == x&&v[2][0] == x)return true;
	return false;
}
signed main() {
	vector<string>v(3);
	while (cin >> v[0], v[0] != "0") {
		cin >> v[1] >> v[2];
		if (check(v, 'b'))cout << 'b' << endl;
		else if (check(v, 'w'))cout << "w" << endl;
		else cout << "NA" << endl;
	}
	return 0;
}

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

C++: #include <iostream>

using namespace std;

int main(){
  string s[3];

  while(cin >> s[0], s[0] != "0"){
    for(int i = 1 ; i < 3 ; i++){
      cin >> s[i];
    }   

    bool end = false;
    for(int i = 0 ; i < 3 ; i++){
      char ch = s[i][0];
      bool ok = true;
      for(int j = 1 ; j < 3 ; j++){
	if(s[i][j] != ch || s[i][j] == '+'){
	  ok = false;
	  break;
	}
      }
      if(ok){
	cout << ch << endl;
	end = true;
	break;
      }
    }

    if(end){
      continue;
    }  

    for(int i = 0 ; i < 3 ; i++){
      char ch = s[0][i];
      bool ok = true;
      for(int j = 1 ; j < 3 ; j++){
	if(s[j][i] != ch || s[j][i] == '+'){
	  ok = false;
	  break;
	}
      }
      if(ok){
	cout << ch << endl;
	end = true;
	break;
      }
    }
    if(end){
      continue;
    }

    char ch = s[0][0];
    bool ok = true;
    for(int i = 1 ; i < 3 ; i++){
      if(ch != s[i][i] || ch == '+'){
	ok = false;
	break;
      }
    }

    if(ok){
      cout << ch << endl;
      continue;
    }

    ch = s[0][2];
    ok = true;
    for(int i = 1 ; i < 3 ; i++){
      if(ch != s[i][2-i] || ch == '+'){
	ok = false;
	break;
      }
    }

    if(ok){
      cout << ch << endl;
      break;
    }
    cout << "NA" << endl;
  }

  return 0;
}

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

int main(){
	char board[3][4];
	int i,j;
	char w;
	while(true){
		w='0';
		for(i=0;i<3;i++){
			cin>>board[i];
			if(board[i][0] == '0' && board[i][1] == '\0'){
				break;
			}
		}
		if(i<3) break;
		for(i=0;i<3;i++){
			if(board[i][0]==board[i][1] && board[i][0]==board[i][2] && board[i][0] != '+'){
				w=board[i][0];
				break;
			}
		}
		for(i=0;i<3;i++){
			if(board[0][i]==board[1][i] && board[0][i]==board[2][i] && board[0][i] != '+'){
				w=board[0][i];
				break;
			}
		}
		if(board[0][0] == board[1][1] && board[0][0] == board[2][2] && board[0][0] != '+'){
			w=board[0][0];
		}
		if(board[0][2] == board[1][1] && board[0][2] == board[2][0] && board[0][0] != '+'){
			w=board[0][2];
		}
		switch(w){
			case '0': cout << "NA\n"; break;
			case 'b': cout << "b\n"; break;
			case 'w': cout << "w\n"; break;
		}
	}
	return 0;
}