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

int main() {
	while(1) {
		vector<string> v;
		for(int i = 0; i < 3; i++) {
			string str;
			cin >> str;
			if(str == "0")
				goto EXIT;
			v.push_back(str);
		}

		for(int i = 0; i < 2; i++) {
			bool tate, yoko;
			bool naname0, naname1;
			char c;
			naname0 = naname1 = false;
			c = i ? 'b': 'w';
			for(int j = 0; j < 3; j++) {
				tate = yoko = true;
				for(int k = 0; k < 3; k++) {
					tate &= v[k][j] == c;
					yoko &= v[j][k] == c;
				}
				naname0 &= v[j][2-j] == c;
				naname1 &= v[j][j] == c;
				if(tate || yoko) {
					cout << c << endl;
					goto NEXT;
				}
			}
			if(naname0 || naname1) {
				cout << c << endl;
				goto NEXT;
			}
		}
		cout << "NA" << endl;
NEXT:;
	}
EXIT:;
}

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

using namespace std;


int main() {

  string buf;

  int board[3][3];


  while(getline(cin,buf)) {

    if(buf[0]=='0') break;

    for(int i=0;i<3;i++) {

      switch(buf[i]) {
	  
      case '+':
	board[0][i]=0;
	break;

      case 'b':
	board[0][i]=1;
	break;

      case 'w':
	board[0][i]=2;
	break;

      }

    }

    for(int i=1;i<3;i++) {

      getline(cin,buf);

      for(int j=0;j<3;j++) {

	switch(buf[j]) {
	  
	case '+':
	  board[i][j]=0;
	  break;

	case 'b':
	  board[i][j]=1;
	  break;

	case 'w':
	  board[i][j]=2;
	  break;

	}

      }

    }
    /*
    for(int i=0;i<3;i++) {

      for(int j=0;j<3;j++) cout << board[i][j];

      cout << endl;

    }
    */
    if((board[0][0]==1 && board[0][1]==1 && board[0][2]==1) || (board[1][0]==1 && board[1][1]==1 && board[1][2]==1) || (board[2][0]==1 && board[2][1]==1 && board[2][2]==1) || (board[0][0]==1 && board[1][0]==1 && board[2][0]==1) || (board[0][1]==1 && board[1][1]==1 && board[2][1]==1) || (board[0][2]==1 && board[1][2]==1 && board[2][2]==1) || (board[0][0]==1 && board[1][1]==1 && board[2][2]==1) || (board[0][2]==1 && board[1][1]==1 && board[2][0]==1)) cout << "b" << endl;

    else if((board[0][0]==2 && board[0][1]==2 && board[0][2]==2) || (board[1][0]==2 && board[1][1]==2 && board[1][2]==2) || (board[2][0]==2 && board[2][1]==2 && board[2][2]==2) || (board[0][0]==2 && board[1][0]==2 && board[2][0]==2) || (board[0][1]==2 && board[1][1]==2 && board[2][1]==2) || (board[0][2]==2 && board[1][2]==2 && board[2][2]==2) || (board[0][0]==2 && board[1][1]==2 && board[2][2]==2) || (board[0][2]==2 && board[1][1]==2 && board[2][0]==1)) cout << "w" << endl;

    else cout << "NA" << endl;

  }

  return 0;

}

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

int main(void)
{
	string board[3];
	string set[2];
	string y_comp;
	string t_comp;
	string l_comp;
	string r_comp;
	char str[4];
	bool flag = false, n_flag = false;
	
	set[0] = "bbb";
	set[1] = "www";
	
	while (1){
		n_flag = false;
		for (int i = 0; i < 3; i++){
			scanf("%s", str);
			if (str[0] == '0') {
				flag = true;
				break;
			}
			board[i] = str;					
		}
		if (flag) break;
		
		for (int i = 0; i < 3; i++){
			for (int j = 0; j < 3; j++){
				y_comp += board[i][j];
				t_comp += board[j][i];
				if (i + j == 2) l_comp += board[i][j];
			}
			if (y_comp == set[0] || t_comp == set[0]) {
				printf("b\n");
				n_flag = true;
			}
			else if (y_comp == set[1] || t_comp == set[1]) {
				printf("w\n");
				n_flag = true;
			}
			y_comp.clear();
			t_comp.clear();
			
			r_comp += board[i][i];
		}
		if (r_comp == set[0] || l_comp == set[0]) {
			printf("b\n");
			n_flag = true;
		}
		else if (r_comp == set[1] || l_comp == set[1]) {
			printf("w\n");
			n_flag = true;
		}
		r_comp.clear();
		l_comp.clear();
		if (!n_flag) puts("NA");
	}
	
	return (0);
}

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

char T[3][3];

string blackwhite() {
	for (int i = 0; i < 3; i++) {
		if (T[i][0] == T[i][1] && T[i][1] == T[i][2]) {
			if (T[i][0] == 'b') { return "b"; }
			if (T[i][0] == 'w') { return "w"; }
		}
	}
	for (int i = 0; i < 3; i++) {
		if (T[0][i] == T[1][i] && T[1][i] == T[2][i]) {
			if (T[0][i] == 'b') { return "b"; }
			if (T[0][i] == 'w') { return "w"; }
		}
	}
	if (T[0][0] == T[1][1] && T[1][1] == T[2][2]) {
		if (T[0][0] == 'b') { return "b"; }
		if (T[0][0] == 'w') { return "w"; }
	}
	if (T[0][2] == T[1][1] && T[1][1] == T[2][0]) {
		if (T[0][2] == 'b') { return "b"; }
		if (T[0][2] == 'w') { return "w"; }
	}
	return "NA";
}

int main() {
	while (true) {
		cin >> T[0][0];
		if (T[0][0] == '0') { break; }
		cin >> T[0][1];
		cin >> T[0][2];
		for (int i = 1; i < 3; i++) {
			for (int j = 0; j < 3; j++){
				cin>>T[i][j];
			}
		}
		cout << blackwhite() << endl;
	}
}

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

int main(){
  string s[3];
  while(cin>>s[0]&&s[0]!="0"){
    cin>>s[1]>>s[2];
    bool ak=false,bk=false;
    for(int i=0;i<3;i++){
      bool ak1=true,ak2=true;
      bool bk1=true,bk2=true;
      for(int j=0;j<3;j++){
	if(s[i][j]!='w')ak1=false;
	if(s[j][i]!='w')ak2=false;
	if(s[i][j]!='b')bk1=false;
	if(s[j][i]!='b')bk2=false;
      }
      if(ak1||ak2)ak=true;
      if(bk1||bk2)bk=true;
    }
    int dx[2][3]={{0,1,2},{0,1,2}};
    int dy[2][3]={{0,1,2},{2,1,0}};
    for(int i=0;i<2;i++){
      bool ak1=true,bk1=true;
      for(int j=0;j<3;j++){
	if(s[dx[i][j]][dy[i][j]]!='w')ak1=false;
	if(s[dx[i][j]][dy[i][j]]!='b')bk1=false;
      }
      if(ak1)ak=true;
      if(bk1)bk=true;
    }
    if(ak)cout<<"w"<<endl;
    if(bk)cout<<"b"<<endl;
    if(!(ak+bk))cout<<"NA"<<endl;
  }
  return 0;
}

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

bool win_check(char c, char d, char e)
{
  if ( c == 'b' && d == 'b' && e == 'b' )
  {
    cout << 'b' << endl;
    return true;
  }
  else if ( c == 'w' && d == 'w' && e == 'w' )
  {
    cout << 'w' << endl;
    return true;
  }
  return false;
}

int main()
{
  while (true)
  {
    char board[3][3];
    for (int i=0; i<3; i++)
    {
      for (int j=0; j<3; j++)
      {
        cin >> board[i][j];
        if (board[i][j] == '0') return 0;
      }
    }

    bool flag = false;

    for (int i=0; i<3; i++)
    {
      flag = win_check(board[i][0], board[i][1], board[i][2]);
      if ( flag ) break;
    }
    if ( flag ) continue;
    
    for (int j=0; j<3; j++)
    {
      flag = win_check(board[0][j], board[1][j], board[2][j]);
      if ( flag ) break;
    }
    if ( flag ) continue;

    flag = win_check(board[0][0], board[1][1], board[2][2]);
    if ( flag ) continue;
    flag = win_check(board[0][2], board[1][1], board[2][0]);
    if ( flag ) continue;

    cout << "NA" << endl;
  }
}