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++: #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 <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <bitset>
using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;

#define rep(i,n) for(int i=0; i<n; i++)
#define repa(i,s,e) for(int i=s; i<=e; i++)
#define repd(i,s,e) for(int i=s; i>=e; i--)

char B[3][3];

char check() {
	bool ok = false;
	rep(i,3) {
		ok = true;
		rep(j,3) {
			if(B[i][0] != B[i][j]) {
				ok = false;
				break;
			}
		}
		if(ok) return B[i][0];
	}

	rep(i,3) {
		ok = true;
		rep(j,3) {
			if(B[0][i] != B[j][i]) {
				ok = false;
				break;
			}
		}
		if(ok) return B[0][i];
	}

	rep(i,3) {
		ok = true;
		if(B[1][1] != B[i][i]) {
			ok = false;
			break;
		}

		if(B[1][1] != B[i][2-i]) {
			ok = false;
			break;
		}
	}
	if(ok) return B[1][1];
	
	return '+';
}

int main() {
	while( 1 ) {
		rep(i,3) {
			rep(j,3) {
				cin >> B[i][j];
				if(i==0 && j==0 && B[i][j] == '0') return 0;
			}
		}

		char a = check();
		if(a == '+') printf("NA\n");
		else printf("%c\n", a);
	}
}

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

bool solve(const vector<string>& board, char c)
{
  if (board[0][0] == c && board[0][1] == c && board[0][2] == c ||
      board[1][0] == c && board[1][1] == c && board[1][2] == c ||
      board[2][0] == c && board[2][1] == c && board[2][2] == c ||
      board[0][0] == c && board[1][0] == c && board[2][0] == c ||
      board[0][1] == c && board[1][1] == c && board[2][1] == c ||
      board[0][2] == c && board[1][2] == c && board[2][2] == c ||
      board[0][0] == c && board[1][1] == c && board[2][2] == c ||
      board[2][0] == c && board[1][1] == c && board[0][2] == c)
    return true;
  return false;
}

int main()
{
  vector<string> board(3);
  while (cin >> board[0] >> board[1] >> board[2]) {
    if (board[0] == "0")
      break;

    if (solve(board, 'b'))
      cout << "b" << endl;
    else if (solve(board, 'w'))
      cout << "w" << endl;
    else
      cout << "NA" << endl;
  }
  return 0;
}

C++: #include "bits/stdc++.h"

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

char solve(string data[3]){
	rep(i,3){
		if( data[i][0]==data[i][1] && data[i][1]==data[i][2] && data[i][0]!='+' ){
			return data[i][0];
		}
	}
	rep(i,3){
		if( data[0][i]==data[1][i] && data[1][i]==data[2][i] && data[0][i]!='+' ){
			return data[0][i];
		}
	}
	if( data[0][0]==data[1][1] && data[1][1]==data[2][2] && data[0][0]!='+' )return data[1][1];
	if( data[0][2]==data[1][1] && data[1][1]==data[2][0] && data[1][1]!='+' )return data[1][1];


	return '+';
}


int main(){
	string s;
	while(cin>>s){
		string data[3];
		if(s=="0")break;
		data[0]=s;
		rep(i,2)cin>>data[i+1];

		char res = solve(data);
		if(res=='+')cout<<"NA"<<endl;
		else cout<<res<<endl;
	}
}

C++: #include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iostream>
#include <cctype>
#include <sstream>
#include <string>
#include <list>
#include <vector>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <utility>
#include <numeric>
#include <algorithm>
#include <iterator>
#include <bitset>
#include <complex>
#include <fstream>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
template<class T> T RoundOff(T a){ return int(a+.5-(a<0)); }
template<class T, class C> void chmax(T& a, C b){ if(a < b) a = b; }
template<class T, class C> void chmin(T& a, C b){ if(b < a) a = b; }
template<class T, class C> pair<T, C> mp(T a, C b){ return make_pair(a, b); }

string board[3];

bool row(char c)
{
	rep(i, 3) rep(j, 3)
	{
		if(board[i][j] != c) break;
		else if(j == 2) return true;
	}
	
	return false;
}

bool column(char c)
{
	rep(i, 3) rep(j, 3)
	{
		if(board[j][i] != c) break;
		else if(j == 2) return true;
	}
	
	return false;
}

bool diagonal(char c)
{
	rep(i, 3)
	{
		if(board[i][i] != c) break;
		else if(i == 2) return true;
	}
	
	rep(i, 3)
	{
		if(board[2 - i][i] != c) break;
		else if(i == 2) return true;
	}
	
	return false;
}

bool (*pred[3])(char) = {row, column, diagonal};
char ch[2] = {'b', 'w'};

int main()
{
    while(cin >> board[0] && board[0] != "0")
	{
		rep(i, 2) cin >> board[i + 1];
		
		rep(i, 3)
		{
			if(i == 2) cout << "NA" << endl;
			else rep(j, 3) if(pred[j](ch[i]))
			{
				cout << ch[i] << endl;
				goto ng;
			}
		}
		
	ng:;
	}
}