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")
		}
	}
}

Python: def b_or_w(b_1, b_2, b_3):
    b, w = 'bbb', 'www'
    board = [b_1, b_2, b_3]
    for i in range(3):
        col = b_1[i] + b_2[i] + b_3[i]
        board.append(col)
    board.append(b_1[0] + b_2[1] + b_3[2])
    board.append(b_1[2] + b_2[1] + b_3[0])
    for bod in board:
        if bod == b:
            return 'b'
        elif bod == w:
            return 'w'
    else:
        return 'NA'

while True:
    b_1 = input()
    if b_1 == '0': break
    b_2, b_3 = input(), input()
    print(b_or_w(b_1, b_2, b_3))

Python: # -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0183

"""
import sys
from sys import stdin
input = stdin.readline


def solve(board):
    colors = ['b', 'w']
    for c in colors:
        for y in range(3):
            if board[y].count(c) == 3:
                return c
        for x in range(3):
            if board[0][x] == c and board[1][x] == c and board[2][x] == c:
                return c
        if board[0][0] == c and board[1][1] == c and board[2][2] == c:
            return c
        if board[0][2] == c and board[1][1] == c and board[2][0] == c:
            return c
    return 'NA'


def main(args):
    while True:
        temp = input().strip()
        if temp[0] == '0':
            break
        board = []
        board.append(list(temp))
        board.append(list(input().strip()))
        board.append(list(input().strip()))
        result = solve(board)
        print(result)


if __name__ == '__main__':
    main(sys.argv[1:])

Python: import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


table = [[] for row in range(3)]

def check(mark):
    global table

    for row in range(3):
        count = 0;
        for col in range(3):
            if table[row][col] == mark:
                count += 1
        if count == 3:
            return True

    for col in range(3):
        count = 0
        for row in range(3):
            if table[row][col] == mark:
                count += 1
        if count == 3:
            return True

    if table[1][1] == mark and ((table[0][0] == mark and table[2][2] == mark) or
            (table[0][2] == mark and table[2][0] == mark)):
        return True
    else:
        return False


while True:
    input_str = input()
    if input_str[0] == "0":
        break
    table[0] = input_str
    for row in range(1,3):
        table[row] = input()

    black = check("b")
    white = check("w")
    if black == True:
        print("b")
    elif white == True:
        print("w")
    else:
        print("NA")

C++: #include <iostream>

using namespace std;

int main(int argc, char **)
{
	int f;
	char a[3][4];
	
	while(scanf("%s", a[0])!=EOF){
		if(a[0][0] == '0'){
			break;
		}
		f = 0;
		scanf("%s", a[1]);
		scanf("%s", a[2]);
		for(int i = 0; i < 3; i++){
			if(a[0][i] == a[1][i] && a[0][i] == a[2][i] && (a[0][i] == 'w' || a[0][i] == 'b')){
				cout << a[0][i] << endl;
				f = 1;
				break;
			} else if(a[i][0] == a[i][1] && a[i][0] == a[i][2] && (a[i][0] == 'w' || a[i][0] == 'b')){
				cout << a[i][0] << endl;
				f = 1;
				break;
			}
		}
		if(f == 0){
			if(a[0][0] == a[1][1] && a[0][0] == a[2][2] && (a[0][0] == 'w' || a[0][0] == 'b')){
				cout << a[0][0] << endl;
			} else if(a[0][2] == a[1][1] && a[0][2] == a[2][0] && (a[1][1] == 'w' || a[1][1] == 'b')){
				cout << a[1][1] << endl;
			} else {
				cout << "NA" << endl;
			}
		}
	}
}

C++: #include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    char f[3][4];
    while(scanf("%s",f[0]),f[0][0]!='0'){
        for(int i=1;i<3;i++)scanf("%s",f[i]);
        char ans=0;
        for(int i=0;i<3;i++){
            if(f[0][i]==f[1][i]&&f[1][i]==f[2][i]&&f[2][i]!='+')ans=f[0][i];
            if(f[i][0]==f[i][1]&&f[i][1]==f[i][2]&&f[i][2]!='+')ans=f[i][0];
        }
        if(f[0][0]==f[1][1]&&f[1][1]==f[2][2]&&f[1][1]!='+')ans=f[0][0];
        if(f[0][2]==f[1][1]&&f[1][1]==f[2][0]&&f[1][1]!='+')ans=f[0][2];

        if(ans==0)printf("NA\n");
        else printf("%c\n",ans);
    }
    return 0;
}

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

#define BLACK 'b'
#define WHITE 'w'
#define SPACE '+'

using namespace std;


char isWin(string data[3]) {
  char temp;
  temp = data[0][0];
  if(temp != SPACE && data[1][1] == temp && data[2][2] == temp) return temp;
  temp = data[2][0];
  if(temp != SPACE && data[1][1] == temp && data[0][2] == temp) return temp;

  for(int i = 0; i < 3; i++) {
    temp = data[i][0];
    if(temp == SPACE) continue;
    bool flag = true;
    for(int j = 0; j < 3; j++) {
      if(data[i][j] != temp) {
	 flag = false;
	 break;
      }
    }
    if(flag) {
      return temp;
    }
  }

  for(int i = 0; i < 3; i++) {
    temp = data[0][i];
    if(temp == SPACE) continue;
    bool flag = true;
    for(int j = 0; j < 3; j++) {
      if(data[j][i] != temp) {
	 flag = false;
	 break;
      }
    }
    if(flag) {
      return temp;
    }
  }

  return SPACE;
}

int main() {
  while(1) {
    string data[3];
    getline(cin, data[0]);
    if(data[0] == "0") break;
    for(int i = 1; i < 3; i++) {
      getline(cin, data[i]);
    }

    char temp = isWin(data);
    if(temp == SPACE) {
      cout << "NA" << endl;
    } else {
      cout << temp << endl;
    }
  }
  return 0;
}

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 ? "a" : winner == -1 ? "b" : "NA");

	}
}