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 <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];
	}

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

	ok = true;
	rep(i,3) {
		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<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<string>
#include<cstring>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
#include<bitset>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define ll2(x, y) ll x, y; cin >> x >> y;
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << (x) << "\n"
#define debug2(x, y) cout << " --- " << (x) << " " << (y) << "\n"
#define debug3(x, y, z) cout << " --- " << (x) << " " << (y) << " " << (z) << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

string s[3];
signed main(void){
  int i, j;
  for(int testcase = 0;testcase >= 0;testcase++){
    cin >> s[0] >> s[1] >> s[2];
    if(s[0][0] == '0')break;

    rep(i, 3){
      rep(j, 3)if(s[i][0] != s[i][j])break;
      if(j == 3 && s[i][0] != '+'){
        cout << s[i][0] << endl;
        break;
      }
      rep(j, 3)if(s[0][i] != s[j][i])break;
      if(j == 3 && s[0][i] != '+'){
        cout << s[0][i] << endl;
        break;
      }
    }
    if(i == 3){
      if(s[0][0] == s[1][1] && s[1][1] == s[2][2] && s[0][0] != '+'){
        cout << s[0][0] << endl;
        continue;
      }
      if(s[0][2] == s[1][1] && s[1][1] == s[2][0] && s[2][0] != '+'){
        cout << s[0][2] << endl;
        continue;
      }
      puts("NA");
    }



//*/

//*/ break;
  }
  return 0;
}

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

int main(){
  while(true){
    string brd[3];
    bool bWin=false;
    bool wWin=false;
    for(int i = 0; i < 3; ++i){
      cin >> brd[i];
      if( brd[i] == "0") return 0;
    }
    
    // row
    for(int i = 0; i < 3; ++i){
      int b=0,w=0;
      for(int j = 0; j < 3; ++j){
	if(brd[i][j]=='b')++b;
	else if(brd[i][j]=='w')++w;
      }
      if(b==3)bWin=true;
      if(w==3)wWin=true;
    }
    
    // col
    for(int j = 0; j < 3; ++j){
      int b=0,w=0;
      for(int i = 0; i < 3; ++i){
	if(brd[i][j]=='b')++b;
      if(brd[i][j]=='w')++w;
      }
      if(b==3)bWin=true;
      if(w==3)wWin=true;
    }
    
    // diagonal
    int b=0,w=0;
    for(int i = 0; i < 3; ++i){
      if( brd[i][i] == 'b' ) ++b;
    if( brd[i][i] == 'w' ) ++w;
    }
    if(b==3)bWin=true;
    if(w==3)wWin=true;
    
    b=0,w=0;
    for(int i = 0; i < 3; ++i){
      if( brd[i][2-i] == 'b' ) ++b;
      if( brd[i][2-i] == 'w' ) ++w;
    }
    if(b==3)bWin=true;
    if(w==3)wWin=true;
    
    if( (bWin && wWin) || (!bWin && !wWin) ){
      cout << "NA" << endl;
    }else if(bWin)
      cout << 'b' << endl;
    else
      cout << 'w' << endl;
  }
  
  return 0;
}

C++: #include<iostream>
using namespace std;
int main(void) {
	while (1) {
		char c;
		int goban[3][3] = { 0 }, result = 0, judge = 0;
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				cin >> c;
				if (c == '0') return 0;
				if (c == 'b')goban[i][j] = 1;
				else if (c == 'w')goban[i][j] = -1;
				else goban[i][j] = 0;
			}
		}
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				judge += goban[i][j];
			}
			if (judge == 3) result = 1;
			else if (judge == -3) result = -1;

			judge = 0;
		}
		for (int j = 0; j < 3; j++) {
			for (int i = 0; i < 3; i++) {
				judge += goban[i][j];
			}
			if (judge == 3) result = 1;
			else if (judge == -3) result = -1;

			judge = 0;
		}
		for (int i = 0; i < 3; i++) {
			judge += goban[i][i];
		}
		if (judge == 3) result = 1;
		else if (judge == -3) result = -1;

		judge = 0;

		for (int i = 0; i < 3; i++) {
			judge += goban[i][2 - i];
		}
		if (judge == 3) result = 1;
		else if (judge == -3) result = -1;

		judge = 0;


		if (result == 1) {
			cout << "b" << endl;
		}
		else if (result == -1) {
			cout << "w" << endl;
		}
		else {
			cout << "NA" << endl;
		}
	}
}