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 <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define INF 1<<30

char ba[3][3];

bool judge(char c) {
  REP(i,3) {
    int ct1 = 0, ct2 = 0;
    REP(j,3) {
      if (ba[i][j] == c) ct1++;
      if (ba[j][i] == c) ct2++;
    }
    if (ct1 == 3 || ct2 == 3) return true;
  }
  int ct1 = 0, ct2 = 0;
  REP(i,3) {
    if (ba[i][i] == c) ct1++;
    if (ba[2-i][i] == c) ct2++;
  }
  if (ct1 == 3 || ct2 == 3) return true;
  return false;
}

int main() {
  char a;
  while(cin >> a, a!='0') {
    ba[0][0] = a;
    REP(i,3) {
      REP(j,3) {
        if (i||j)
          cin >> ba[j][i];
      }
    }
    if (judge('b')) cout << 'b' << endl;
    else if (judge('w')) cout << "w" << endl;
    else cout << "NA" << endl;
  }
}

C++: #include <bits/stdc++.h>
using namespace std;
int main() {
	string s[3];
	while (cin >> s[0]) {
		if (s[0] == "0")
			break;
		cin >> s[1] >> s[2];
		if (s[0][0] != '+' && s[0][0] == s[0][1] && s[0][1] == s[0][2]) {
			cout << s[0][0] << endl;
			continue;
		}
		if (s[1][0] != '+' && s[1][0] == s[1][1] && s[1][1] == s[1][2]) {
			cout << s[1][0] << endl;
			continue;
		}
		if (s[2][0] != '+' && s[2][0] == s[2][1] && s[2][1] == s[2][2]) {
			cout << s[2][0] << endl;
			continue;
		}
		if (s[0][0] != '+' && s[0][0] == s[1][0] && s[1][0] == s[2][0]) {
			cout << s[0][0] << endl;
			continue;
		}
		if (s[0][1] != '+' && s[0][1] == s[1][1] && s[1][1] == s[2][1]) {
			cout << s[0][1] << endl;
			continue;
		}
		if (s[0][2] != '+' && s[0][2] == s[1][2] && s[1][2] == s[2][2]) {
			cout << s[0][2] << endl;
			continue;
		}
		if (s[0][0] != '+' && s[0][0] == s[1][1] && s[1][1] == s[2][2]) {
			cout << s[0][0] << endl;
			continue;
		}
		if (s[0][2] != '+' && s[0][2] == s[1][1] && s[1][1] == s[2][0]) {
			cout << s[0][2] << endl;
			continue;
		}
		cout << "NA" << endl;
	}
	return 0;
}

C++: #include <bits/stdc++.h>

using namespace std;


string MapData[3];

void judge() {
	for (int i = 0; i < 3; i++) {
		//judgeByRow
		if (MapData[i][0] != '+' && MapData[i][0] == MapData[i][1] && MapData[i][1] == MapData[i][2]) {
			cout << MapData[i][0] << endl;
			return;
		}

		//judgeByCol
		if (MapData[0][i] != '+' && MapData[0][i] == MapData[1][i] && MapData[1][i] == MapData[2][i]) {
			cout << MapData[0][i] << endl;
			return;
		}
	}

	if (MapData[0][0] != '+' && MapData[0][0] == MapData[1][1] && MapData[1][1] == MapData[2][2]) {
		cout << MapData[0][0] << endl;
		return;
	}
	if (MapData[0][2] != '+' && MapData[0][2] == MapData[1][1] && MapData[1][1] == MapData[2][0]) {
		cout << MapData[0][2] << endl;
		return;
	}

	cout << "NA" << endl;
}

int main() {

	while (1) {
		cin >> MapData[0];
		if (MapData[0][0] == '0') {
			break;
		}
		cin >> MapData[1] >> MapData[2];

		judge();
	}
	return 0;
}

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

using namespace std;

char s[3][3];

int judgeB(){
  for(int i = 0; i < 3; i++){
    if(s[i][0] == 'b' && s[i][1] == 'b' && s[i][2] == 'b') return 1;
  }
  for(int i = 0; i < 3; i++){
    if(s[0][i] == 'b' && s[1][i] == 'b' && s[2][i] == 'b') return 1;
  }
  if(s[0][0] == 'b' && s[1][1] == 'b' && s[2][2] == 'b') return 1;
  if(s[0][2] == 'b' && s[1][1] == 'b' && s[2][0] == 'b') return 1;

  return 0;
}

int judgeW(){
  for(int i = 0; i < 3; i++){
    if(s[i][0] == 'w' && s[i][1] == 'w' && s[i][2] == 'w') return 1;
  }
  for(int i = 0; i < 3; i++){
    if(s[0][i] == 'w' && s[1][i] == 'w' && s[2][i] == 'w') return 1;
  }
  if(s[0][0] == 'w' && s[1][1] == 'w' && s[2][2] == 'w') return 1;
  if(s[0][2] == 'w' && s[1][1] == 'w' && s[2][0] == 'w') return 1;

  return 0;
}


int main(){
 
  while(1){

    for(int j = 0; j < 3; j++){
      for(int k = 0; k < 3; k++){
	cin >> s[j][k];
	if(s[j][k] == '0') return 0;
      }
    }

    int x = judgeB();
    int y = judgeW();

    if(x == 1) cout << "b" << endl;
    else if(y == 1) cout << "w" << endl;
    else cout << "NA" << endl;
  }
  
  return 0;
}

C++: #include<iostream>
#include<string>
using namespace std;
int main() {
	string a;
	while (cin >> a&&a != "0") {
		char b[3][3];
		for (int i = 0; i < 3; i++)
			b[0][i] = a[i];
		for (int i = 1; i < 3; i++) {
			cin >> a;
			for (int j = 0; j < 3; j++) 
				b[i][j] = a[j];
		}
		string e;
		for (int i = 0; i < 3; i++) {
			bool c = true;
			char d = b[i][0];
			for (int j = 1; j < 3; j++) {
				if (b[i][j] != d||d=='+') 
					c = false;
			}
			if (c) {
				e = d;
				goto stop;
			}
		}
		for (int i = 0; i < 3; i++) {
			bool c = true;
			char d = b[0][i];
			for (int j = 1; j < 3; j++) {
				if (b[j][i] != d||d=='+')
					c = false;
			}
			if (c) {
				e = d;
				goto stop;
			}
		}
		if (b[0][0] == b[1][1] && b[1][1] == b[2][2]&&b[1][1]!='+') {
			e = b[0][0];
			goto stop;
		}
		if (b[0][2] == b[1][1] && b[1][1] == b[2][0]&&b[1][1]!='+') {
			e = b[1][1];
			goto stop;
		}
		e = "NA";
	stop:;
		cout << e << endl;
	}
}