/*------------------------------------------------------------
TEAM45
A
234
Target: MSVC9; Platform: Win32; Comment: MS Visual C++ 9
------------------------------------------------------------*/
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
#include <vector>

using namespace std;

const int BOARD_SIZE = 8;
const int MAX_MOVES = 3 * BOARD_SIZE * BOARD_SIZE;

const int EMPTY = 0;
const int WHITE = 1;
const int BLACK = -1;

int board[BOARD_SIZE][BOARD_SIZE];
int color;


bool isBoard(int x, int y)
{
	return (0 <= x && x < BOARD_SIZE && 0 <= y && y < BOARD_SIZE);
}


struct Move{

	int sx,sy;
	int ex,ey;
	int is_capture;
	int defense;
	int attack;

	Move() {}

	Move(int _sx, int _sy, int _ex, int _ey) : sx(_sx), sy(_sy), ex(_ex), ey(_ey)
	{
		is_capture = (board[ex][ey] != EMPTY);
		int count[3] = {0, 0, 0};
		for (int i = -1; i <= 1; i += 2)
		{
			for (int j = -1; j <= 1; j += 2)
			{
				if (isBoard(ex + i, ey + j) && board[ex + i][ey + j] == -j)
					++count[j + 1];
			}
		}
		attack = count[-color + 1];
		if (ex != sx)
			--attack;
		defense = count[color + 1];

		if (defense == 0)
			if (attack != 0)
			{
				attack-=1;
			}
	}

	int getForce() const
	{
		return attack - defense;
	}

	bool operator < (const Move & t) const
	{
		if (ey == 0 || ey == BOARD_SIZE - 1)
		{
			//while(1);
			return 1;
		}
		if (t.ey == 0 || t.ey == BOARD_SIZE - 1)
		{
			//while(1);
			return 0;
		}
		if (is_capture != t.is_capture)
			return is_capture > t.is_capture;
		if (getForce() != t.getForce())
			return getForce() > t.getForce();
/*		if (is_capture)
			return (ey * color) < (t.ey * color);
		else*/
			return (ey * color) > (t.ey * color);
	}

	void print()
	{
		fprintf(stderr, "%c%d-%c%d %d %d %d\n", sx + 'a', sy + 1, ex + 'a', ey + 1, is_capture, attack, defense);
	}

};


void init()
{
	memset(board,EMPTY,sizeof(board));
	for(int i = 0; i < BOARD_SIZE; i++)
	{
		board[i][0] = board[i][1] = WHITE;
		board[i][BOARD_SIZE-1] = board[i][BOARD_SIZE - 2] = BLACK;
	}
	color = WHITE;
}

void make_move(Move &move)
{
	board[move.ex][move.ey] = board[move.sx][move.sy];
	board[move.sx][move.sy] = EMPTY;
	color = -color;
}


void make_move(char *str)
{
	char sx, ex;
	int sy, ey;
	sscanf(str, "%c%d%c%d", &sx, &sy, &ex, &ey);
	Move move(sx - 'a', sy - 1, ex - 'a', ey - 1);
	make_move(move);
}


int gen_moves(Move *moves)
{
	int cnt = 0;
	for(int i = 0; i < BOARD_SIZE; i++)
	{
		for(int j = 0; j < BOARD_SIZE; j++)
		{
			if (board[i][j] == color)
			{
				for(int di = -1; di <= 1; di++)
				{
					/*if (di == 0)
						continue;*/
					int ni = i + di;
					int nj = j + color;
					if (isBoard(ni, nj) && board[ni][nj] != color && (di != 0 || board[ni][nj] == EMPTY))
					{
						Move move (i, j, ni, nj);
						moves[cnt++] = move;
					}
				}
			}
		}
	}
	return cnt;
}


int numberMove = 0;
char colors[2][15] = {"White", "Black"};


char getChar(int p)
{
	switch (p)
	{
		case WHITE:
			return 'w';
		case BLACK:
			return 'b';
		case EMPTY:
			return '.';
		default:
			return '-';
	}
}


int getRandomMove(Move *moves, int cnt)
{
	//return 0;
	if (moves[0].ey == 0 || moves[0].ey == BOARD_SIZE - 1)
		return 0;
	vector <double> prob;
	/*prob.push_back(35);
	if (cnt > 7)
	{
		prob.push_back(20);
		prob.push_back(20);
	}
	prob.push_back(7);
	prob.push_back(6);
	prob.push_back(5);
	prob.push_back(4);
	prob.push_back(3);*/
	prob.push_back(10);
	prob.push_back(2);
	prob.push_back(2);
	while ((int)prob.size() < cnt)
		prob.push_back(0);
	prob.resize(cnt);

	double sum = 0;
	for (int i = 0; i < cnt; ++i)
		sum += prob[i];
	for (int i = 0; i < cnt; ++i)
		prob[i] /= sum;
	double f = rand() / double(RAND_MAX);
	int i = 0;
	while (i < cnt - 1 && prob[i] < f)
	{
		f -= prob[i];
		++i;
	}
	return i;
}


void think(char *str)
{
	++numberMove;

	Move moves[MAX_MOVES];
	int cnt=gen_moves(moves);
#ifdef DBG1
	char fname[100];
	sprintf(fname, "moves%s%d.txt", colors[(color != WHITE)], numberMove);
	freopen(fname, "w", stderr);
	sort(moves, moves + cnt);
	for (int i = 0; i < cnt; ++i)
		moves[i].print();
	moves[0].print();
	for (int j = BOARD_SIZE - 1; j >= 0; --j)
	{
		for (int i = 0; i < BOARD_SIZE; ++i)
			fprintf(stderr, "%c", getChar(board[i][j]));
		fprintf(stderr, "\n");
	}
	fflush(stderr);
#endif
	Move &move = moves[getRandomMove(moves, cnt)];
	sprintf(str,"%c%d%c%d", move.sx + 'a', move.sy + 1, move.ex + 'a', move.ey + 1);
	make_move(move);
}


int main()
{
	int seed = (int) time(0);
#ifdef DBG1
	freopen("bing_bong_seed.txt", "w", stderr);
	fprintf(stderr, "%d\n", seed);
#endif
	srand(seed);
	init();
	while(1)
	{
		char str[100];
		gets(str);
		if(strcmp(str,"Name") == 0)
		{
			// Request for the bot name
			printf("Bing Bong Bot\n");
			fflush(stdout);
		}
		else if(strcmp(str,"Quit") == 0)
		{
			// Game is over
			break;
		}
		else
		{
			if(strcmp(str,"Start")!= 0)
			{
				// Enemy's move
				make_move(str);
			}
			// Our move
			think(str);
			printf("%s\n",str);
			fflush(stdout);
		}
	}
	return 0;
}
