import java.util.Random;
import java.util.Scanner;

public class othello4 {

    static class IntPair {
        public int first;
        public int second;
        IntPair(int f, int s) {
            first = f;
            second = s;
        }
    }

    static Random rand = new Random(12345);

    public static IntPair directions[] = new IntPair[8];
    static {
        directions[0] = new IntPair(-1, -1);
        directions[1] = new IntPair( 0, -1);
        directions[2] = new IntPair( 1, -1);
        directions[3] = new IntPair(-1,  0);
        directions[4] = new IntPair( 1,  0);
        directions[5] = new IntPair(-1,  1);
        directions[6] = new IntPair( 0,  1);
        directions[7] = new IntPair( 1,  1);
    }
    
    static int board[][] = new int[8][8];

    static void init_board()
    {
        int c, r; // column, row
        for (r = 0; r < 8; r++) 
            for (c = 0; c < 8; c++)
                board[c][r] = 0;

        board[4][3] = board[3][4] =  1;  // black disks
	board[3][3] = board[4][4] = -1;  // white disks
    }

    static void print_board()
    {
        System.out.printf("\n  a b c d e f g h\n");
        for (int r = 0; r < 8; r++) {
            System.out.printf("%d", r + 1);
            for (int c = 0; c < 8; c++) {
                final int d = board[c][r];
                char s = '.';
                if (d ==  1) s = 'B'; // black disk
                if (d == -1) s = 'W'; // white disk
                System.out.printf(" %c", s);
            }
            System.out.printf("\n");
        }
        System.out.printf("\n");
    }

    static boolean can_flip(final int side, 
                            final IntPair sq0, final IntPair dir) // square, direction
    {
        IntPair sq = new IntPair(sq0.first, sq0.second);
        assert(board[sq.first][sq.second] == 0);
        int n = 0;
        do {
            sq.first  += dir.first; 
            sq.second += dir.second; 
            n++;
            if (sq.first < 0  || sq.first >= 8)  return false;
            if (sq.second < 0 || sq.second >= 8) return false;
        } while (board[sq.first][sq.second] == -side);
        if (board[sq.first][sq.second] == 0) return false;
        if (n <= 1) return false;
        return true;
    }

    static boolean is_legal_move(final int side, final IntPair sq)
    {
        if (sq.first < 0  || sq.first >= 8)  return false;
        if (sq.second < 0 || sq.second >= 8) return false;
        if (board[sq.first][sq.second] != 0) return false;
        for (int i = 0; i < 8; i++) {
            if (can_flip(side, sq, directions[i])) return true;
        }
        return false;
    }

    static int place_disk(final int side, final IntPair sq)
    {
        assert(is_legal_move(side, sq));
        int n = 0;
        for (int i = 0; i < 8; i++) {
            final IntPair dir = directions[i];
            if (!can_flip(side, sq, dir)) continue;
            int c = sq.first  + dir.first;
            int r = sq.second + dir.second;
            while (board[c][r] == -side) {
                board[c][r] = side;
                n++;
                c += dir.first;
                r += dir.second;
            }
        }
        board[sq.first][sq.second] = side;
        assert(n > 0);
        return n;
    }

    static int generate_legal_moves(final int side, IntPair legal_moves[])
    {
        int nmoves = 0, nempty = 0;
        for (int c = 0; c < 8; c++) {
            for (int r = 0; r < 8; r++) {
                if (board[c][r] != 0) continue;
                nempty++;
                IntPair sq = new IntPair(c, r);
                if (!is_legal_move(side, sq)) continue;
                assert(nmoves < 60);
                legal_moves[nmoves++] = sq;
            }
        }
        if (nempty == 0) return -1;
        return nmoves;
    }

    static int count_disks()
    {
        int sum = 0;
        for (int c = 0; c < 8; c++) {
            for (int r = 0; r < 8; r++) {
                sum += board[c][r];
            }
        }
        return sum;
    }

    static int evaluate()
    {
        int sum = 0;
        for (int c = 0; c < 8; c++) {
            for (int r = 0; r < 8; r++) {
                sum += board[c][r];
            }
        }
        return sum;
    }

    static IntPair select_move(int turn)
    {
	int board0[][] = new int[8][8];
  
	int i, c, r;
	for (c = 0; c < 8; c++) {
	    for (r = 0; r < 8; r++) {
		board0[c][r] = board[c][r];
	    }
	}

	IntPair best_move = new IntPair(-1, -1);
	int best_value = -99999;
	IntPair legal_moves[] = new IntPair[60];
	final int nmoves = generate_legal_moves(turn, legal_moves);
	for (i = 0; i < nmoves; i++) {
	    IntPair move = legal_moves[i];
	    place_disk(turn, move);

	    int value = evaluate() * turn;
	    System.out.printf("move = %c%c, value = %d\n", 'a' + move.first, '1' + move.second, value);
	    if (value > best_value) {
		best_value = value;
		best_move = move;
	    }

	    for (c = 0; c < 8; c++) {
		for (r = 0; r < 8; r++) {
		    board[c][r] = board0[c][r];
		}
	    }
	}

	return best_move;
    }

    static class SearchResult {
        final int score;
        final IntPair move;
        SearchResult(int s, IntPair m) {
            score = s;
            move = m;
        }
    }

    static void board_copy(int dest[][], int src[][]) {
        for (int c = 0; c < 8; c++) {
            for (int r = 0; r < 8; r++) {
                dest[c][r] = src[c][r];
            }
        }
    }

    static SearchResult negamax(int depth, int max_depth, int turn)
    {
        if (depth == max_depth) {
            return new SearchResult(turn * evaluate(), new IntPair(-1, -1));
        }

        IntPair legal_moves[] = new IntPair[60];
        final int nmoves = generate_legal_moves(turn, legal_moves);

        if (nmoves <= 0) {
            final SearchResult r = negamax(depth + 1, max_depth, -turn);
            return new SearchResult(-r.score, new IntPair(-1, -1));
        }

        final int board0[][] = new int[8][8];
        board_copy(board0, board);

        int best_score = -99999;
        IntPair best_move = new IntPair(-1, -1);
        for (int i = 0; i < nmoves; i++) {
            final IntPair move = legal_moves[i];
            place_disk(turn, move);

            final SearchResult r = negamax(depth + 1, max_depth, -turn);
            final int score = -r.score;
	    if (depth == 0) {
		System.out.printf("move = %c%c, score = %d\n", 
				  'a' + move.first, '1' + move.second, score);
	    }
            if (score > best_score) {
                best_move = move;
                best_score = score;
            }
            board_copy(board, board0);
        }

        return new SearchResult(best_score, best_move);
    }

    public static void main(String[] args)
    {
        final int human_side = (args.length >= 1) ? Integer.parseInt(args[0]) : 0;

        init_board();
        print_board();
  
        boolean pass[] = { false, false };
        for (int turn = 1;; turn *= -1) {

            IntPair legal_moves[] = new IntPair[60];
            final int nmoves = generate_legal_moves(turn, legal_moves);
            if (nmoves == -1) break;     // no empty square
            if (nmoves ==  0) {
                System.out.printf("turn = %d, move = Pass\n", turn);
                pass[(turn + 1)/2] = true;
                if (pass[(-turn + 1)/2] == true) break; // pass x 2
                continue;  // pass (no legal move)
            }
	    pass[(turn + 1)/2] = false;

            IntPair move = new IntPair(-1, -1);
            if (turn == human_side) {
                do {
                    System.out.printf("Where? ");
                    Scanner scan = new Scanner(System.in);
                    String str = scan.next();
                    final int c = str.charAt(0) - 'a';
                    final int r = str.charAt(1) - '1';
                    move = new IntPair(c, r);
                } while (!is_legal_move(turn, move));
            } else {
                //move = legal_moves[rand.nextInt(nmoves)];
                //move = select_move(turn);
                SearchResult r = negamax(0, 3, turn);
                move = r.move;
                System.out.printf("turn = %d, move = %c%c\n", turn, 'a' + move.first, '1' + move.second);
            }
            place_disk(turn, move);
            print_board();
        }

	final int d = count_disks();
        if (d > 0)      System.out.printf("The winner is Black.\n");
        else if (d < 0) System.out.printf("The winner is White.\n");
        else            System.out.printf("Draw.\n");

  
    }
}
