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<utility>
#include<queue>
#include<functional>
#include<algorithm>
#include<cstring>
#include<vector>
#include<climits>
#include<map>
using namespace std;
#define FOR(i,n) for(int i=0;i<(int)n;i++)
#define FORI(i,k,n) for(int i=k;i<(int)n;i++)
#define ALL(x) (x).begin(),(x).end()
#define INF (2<<25)
typedef pair<int,int> pii;
typedef vector<int> vi;

int main()
{
	while(true)
	{
		string a[3];
		cin>>a[0]>>a[1]>>a[2];
		if(a[0]=="0")break;
		
		bool isdraw=true;
		
		FOR(i,3)
		{
			bool equal[2]={1,1};
			FOR(j,3)
			{
				if(a[i][j]!=a[i][0])equal[0]=false;
				if(a[j][i]!=a[0][i])equal[1]=false;
			}
			FOR(j,2)
			{
				if(equal[j]&&a[(j?0:i)][j?i:0]!='+')
				{
					isdraw=false;
					cout<<a[(j?0:i)][j?i:0]<<endl;
				}
			}
		}
		if(isdraw)cout<<"NA"<<endl;
		
	}
}

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*i;
      }
    }
  
    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++: #define _USE_MATH_DEFINES
#define INF 10000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<int,string> P;

static const double eps = 1e-8;

int main(){
	char table[5][5];
	while(~scanf("%s",table)){
		if(table[0][0] == '0') break;
		for(int i=1;i<=2;i++){
			scanf("%s",table+i);
		}

		int winner=0;
		for(int i=0;i<3;i++){
			int a=0,b=0;
			for(int j=0;j<3;j++){
				if(table[i][j] == 'a') a++;
				if(table[i][j] == 'b') b++;
			}
			if(a==3) winner = 1;
			if(b==3) winner = -1;
		}

		for(int i=0;i<3;i++){
			int a=0,b=0;
			for(int j=0;j<3;j++){
				if(table[j][i] == 'a') a++;
				if(table[j][i] == 'b') b++;
			}
			if(a==3) winner = 1;
			if(b==3) winner = -1;
		}

		if(table[0][0] == table[1][1]
		&& table[1][1] == table[2][2]
		&& table[2][2] =='a') winner = 1;

		if(table[0][0] == table[1][1]
		&& table[1][1] == table[2][2]
		&& table[2][2] =='b') winner = -1;

		if(table[0][2] == table[1][1]
		&& table[1][1] == table[2][0]
		&& table[2][0] =='a') winner = 1;

		if(table[0][2] == table[1][1]
		&& table[1][1] == table[2][0]
		&& table[2][0] =='b') winner = 1;

		printf("%s\n", winner == 1 ? "w" : winner == -1 ? "b" : "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){
  int b,w;
  
  string str[3];
  int cnt = 0 ;
  while(getline(cin,str[cnt]),str[cnt]!="0"){
    if(cnt==2){
      if(str[0][0] == str[0][1] && str[0][1] == str[0][2])cout<<str[0][1];
      else if(str[1][0] == str[1][1] && str[1][1] == str[1][2])cout<<str[1][1];
      else if(str[2][0] == str[2][1] && str[2][1] == str[2][2])cout<<str[2][1];


      else if(str[0][0] == str[1][0] && str[1][0] == str[2][0])cout<<str[0][0];
      else if(str[0][1] == str[1][1] && str[1][1] == str[2][1])cout<<str[0][1];
      else if(str[0][2] == str[1][2] && str[1][2] == str[2][2])cout<<str[0][2];
      
      else if(str[0][0] == str[1][1] && str[1][1] == str[2][2])cout<<str[0][0];
      else if(str[0][2] == str[1][1] && str[1][1] == str[2][0])cout<<str[0][2];
      else cout<<"NA";
      cout<<endl;
      b = w = 0;
      cnt = -1;
    }
    cnt++;
  }
  return 0;
}

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;
      continue;
    }
    cout << "NA" << endl;
  }

  return 0;
}

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

int main()
{
	string s[3];
	
	while (cin >> s[0], s[0] != "0"){
		cin >> s[1] >> s[2];
		
		
		for (int i = 0; i < 3; i++){
			if (s[i] == "www"){
				cout << "w" << endl;
				break;
			}
			else if (s[i] == "bbb"){
				cout << "b" << endl;
				break;
			}
			else if (s[0][i] == 'w' && s[1][i] == 'w' && s[2][i] == 'w'){
				cout << "w" << endl;
				break;
			}
			else if (s[0][i] == 'b' && s[1][i] == 'b' && s[2][i] == 'b'){
				cout << "b" << endl;
				break;
			}
			else if (s[0][0] == 'w' && s[1][1] == 'w' && s[2][2] == 'w'){
				cout << "w" << endl;
				break;
			}
			else if (s[0][0] == 'b' && s[1][1] == 'b' && s[2][2] == 'b'){
				cout << "b" << endl;
				break;
			}
			else {
				cout << "NA" << endl;
				break;
			}
		}
		
	}
	
	return (0);
}