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 <stdio.h>

#define NON 0
#define BLK 1
#define WHT -1
#define SIZE 3

int isGameSet(int iField[SIZE][SIZE]);

int main(void){
    int board[SIZE][SIZE];
    char buf[4];
    
    while(1){
        for (int y=0; y<SIZE; y++){
            scanf("%s", buf);
            if (buf[0]=='0') return 0;
            for (int x=0; x<SIZE; x++){
                if (buf[x]=='b') board[x][y]=BLK;
                else if (buf[x]=='w') board[x][y]=WHT;
                else if (buf[x]=='+') board[x][y]=NON;
            }
        }
        switch (isGameSet(board)){
        case BLK:
            puts("b"); break;
        case WHT:
            puts("w"); break;
        case NON:
            puts("NA"); break;
        }
    }
    return 0;
}

int isGameSet(int iField[SIZE][SIZE]){
	int i, j;
	int tmp;

	// vertical
	for (i = 0; i < SIZE; i++){
		for (j = 0, tmp = 0; j < SIZE; j++){
			tmp += iField[i][j];
		}
		if (tmp == SIZE*WHT) return WHT;
		if (tmp == SIZE*BLK) return BLK;
	}
	// horizontal
	for (i = 0; i < SIZE; i++){
		for (j = 0, tmp = 0; j < SIZE; j++){
			tmp += iField[j][i];
		}
		if (tmp == SIZE*WHT) return WHT;
		if (tmp == SIZE*BLK) return BLK;
	}
	// diagonal
	for (i = 0, tmp = 0; i < SIZE; i++){
		tmp += iField[i][i];
	}
	if (tmp == SIZE*WHT) return WHT;
	if (tmp == SIZE*BLK) return BLK;
	for (i = 0, tmp = 0; i < SIZE; i++){
		tmp += iField[i][SIZE - 1 - i];
	}
	if (tmp == SIZE*WHT) return WHT;
	if (tmp == SIZE*BLK) return BLK;
	return NON;
}

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

char board[8][8] = {{'+'}};
string ans = "NA";

int main(){
        while (1){
	bool end = false;
	for (int i = 0; i < 3 && !end; i++){
	    for (int j = 0; j < 3 && !end; j++){
		cin >> board[i][j];
		if (board[0][0] == '0') end = true;
	    }
	}

	if (end) break;
	ans = "NA";
	char c = 'b';
	for (int x = 0; x < 3; x++){
	    for (int y = 0; y < 3; y++){
		if (board[x][y] == c && board[x+1][y] == c && board[x+2][y] == c) ans = c;
		if (board[x][y] == c && board[x+1][y+1] == c && board[x+2][y+2] == c) ans = c;
		if (board[x][y] == c && board[x][y+1] == c && board[x][y+2] == c) ans = c;
	    }
	}
	c = 'w';
	for (int x = 0; x < 3; x++){
	    for (int y = 0; y < 3; y++){
		if (board[x][y] == c && board[x+1][y] == c && board[x+2][y] == c) ans = c;
		if (board[x][y] == c && board[x+1][y+1] == c && board[x+2][y+2] == c) ans = c;
		if (board[x][y] == c && board[x][y+1] == c && board[x][y+2] == c) ans = c;
	    }
	}
	cout << ans << endl;
	}
}

C++: #include <cstdio>

int main(){
	char tbl[3][3];
	bool ok, end = false;
	
	for(;;){
		ok = false;
		for(int i = 0; i < 3; i++){
			scanf("%s", &tbl[i]);
			if(tbl[0][0] == '0'){
				end = true;
				break;
			}
		}
		if(end) break;
		if(tbl[0][0] == tbl[1][1] && tbl[0][0] == tbl[2][2] 
			|| tbl[0][2] == tbl[1][1] && tbl[0][2] == tbl[2][0]){
			printf("%c\n", tbl[1][1]);
			ok = true;
		}else {
			for(int i = 0; i < 3; i++){
				if(tbl[i][0] == tbl[i][1] && tbl[i][0] == tbl[i][2]){
					printf("%c\n", tbl[i][0]);
					ok = true;
					break;
				}
				if(tbl[0][i] == tbl[1][i] && tbl[0][i] == tbl[2][i]){
					printf("%c\n", tbl[0][i]);
					ok = true;
					break;
				}
			}
		}
		if(!ok) printf("NA\n");
	}	
	return 0;
}

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){
  char maze[3][3];
  while(cin>>mazze[0][0]){
    if(maze[0][0] == '0')break;
    rep(i,3)rep(j,3){
      if(i==0&&j==0)continue;
      cin>>maze[i][j];
    }
    bool find = false;
    rep(i,3)if(maze[0][i] == maze[1][i] && 
	       maze[1][i] == maze[2][i] && 
	       maze[0][i] != '+'){
      cout<<maze[0][i]<<endl;
      find = true;
    }
    if(find)continue;
    rep(i,3)if(maze[i][0] == maze[1][i] && 
	       maze[i][1] == maze[2][i] && 
	       maze[i][2] != '+'){
      cout<<maze[i][1]<<endl;
      find = true;
    }
    if(find)continue;
    if(maze[0][0] == maze[1][1] && 
       maze[1][1] == maze[2][2] &&
       maze[1][1] != '+'){
      cout<<maze[0][0]<<endl;
      continue;
    }else if(maze[2][0] == maze[1][1] && 
	     maze[1][1] == maze[0][2] &&
	     maze[2][0] != '+'){
      cout<<maze[1][1]<<endl;
      continue;
    }else{
      cout<<"NA"<<endl;
    }
    
  }
  return 0;
}

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

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

using namespace std;

int main()
{
	string s;
	while(cin >> s)
	{
		if(s == "0") break;
		
		vector<string> v;
		v.push_back(s);

		rep(i,2)
		{
			string temp;
			cin >> temp;
			v.push_back(temp);
		}

		bool flag = true;
		string ans = "";

		rep(i,3)
		{
			if(v[i][0] == v[i][1] && v[i][1] == v[i][2])
			{
				if(v[i][0] == 'b' || v[i][0] == 'w')
				{
					cout << v[i][0] << endl;
					flag = false;
					break;
				}
			}

			if(v[0][i] == v[1][i] && v[1][i] == v[2][i])
			{
				if(v[0][i] == 'b' || v[0][i] == 'w')
				{
					cout << v[0][i] << endl;
					flag = false;
					break;
				}
			}
		}

		if(flag)
		{
			if(v[0][0] == v[1][1] && v[1][1] == v[2][2])
			{
				if(v[0][0] == 'b' || v[0][0] == 'w')
				{
					cout << v[0][0] << endl;
					flag = false;
					break;
				}
			}

			else if(v[2][0] == v[1][1] && v[1][1] == v[0][2])
			{
				if(v[2][0] == 'b' || v[2][0] == 'w')
				{
					cout << v[2][0] << endl;
					flag = false;
					break;
				}
			}
		}

		if(flag) cout << "NA" << endl;
	}
	return 0;
}

C++: #include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
typedef complex<double> P;
static const double EPS = 1e-8;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
bool winny(char c,string grid[]){
  REP(y,3){
    bool win = true;
    REP(x,3){
      if(grid[y][x]!=c) win = false;
    }
    if(win) return true;
  }
  REP(x,3){
    bool win = true;
    REP(y,3){
      if(grid[y][x]!=c) win = false;
    }
    if(win) return true;
  }
  bool win = true;
  REP(k,3){
    if(grid[k][k]!=c) win=false;
  }
  if(win) return true;
  win = true;
  REP(k,3){
    if(grid[k][2-k]!=c) win=false;
  }
  if(win) return true;

  return false;
}

int main(void){
  string line;
  while(cin>>line){
    if(line=="0") break;
    string grid[3];
    grid[0] = line;
    REP(i,2)cin>>grid[1+i];
    if(winny('b',grid)) cout<<"b"<<endl;
    else if (winny('w',grid)) cout<<"w"<<endl;
    else cout<<"NA"<<endl;
  }

  return 0;
}