/*------------------------------------------------------------
TEAM34
A
226
Target: MSVC9; Platform: Win32; Comment: MS Visual C++ 9
------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <string>
#include <vector>

using namespace std;

#define BOARD_SIZE 8
#define MAX_MOVES (BOARD_SIZE*2*3)

#define DD(x) 

DD(FILE *fff;)

enum {EMPTY = 0,WHITE = 1,BLACK = 2};

struct game_move 
{
	int sx,sy;
	int ex,ey;
	
	game_move() { sx = sy = ex = ey = -1; }
	game_move(int _sx, int _sy, int _ex, int _ey)
	{
		sx = _sx;
		sy = _sy;
		ex = _ex;
		ey = _ey;
	}
};

inline int op_color(int color) {
	return color==WHITE ? BLACK : WHITE;
}

char board[BOARD_SIZE][BOARD_SIZE];
int MyColor;

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

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

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

void show_move(char *s, game_move move)
{
	sprintf(s, "%c%d%c%d",move.sy+'a',move.sx+1,move.ey+'a',move.ex+1);
}

///////////////////////////////////////////////////////////////

const int MM[2][3][2] = {
	{
		{1, -1},
		{1,  0},
		{1, +1}
	},
	{
		{-1, -1},
		{-1,  0},
		{-1, +1}
	}
};

bool move_is_ok(game_move m)
{
	if (m.sx < 0 || m.sx >= 8) return 0;
	if (m.sy < 0 || m.sy >= 8) return 0;
	if (m.ex < 0 || m.ex >= 8) return 0;
	if (m.ey < 0 || m.ey >= 8) return 0;
	return 1;
}

bool kill_them_all(game_move &move)
{
	for (int x = 0; x < 8; x++)
	for (int y = 0; y < 8; y++)
	{
		if (board[x][y] != MyColor) continue;
		for (int k = 0; k < 3; k += 2)
		{
			move = game_move(x, y, x + MM[MyColor-1][k][0], y + MM[MyColor-1][k][1]);
			if (move_is_ok(move) && board[move.ex][move.ey] == op_color(MyColor)) return 1;
		}
	}
	return 0;
}

int CC = 0;
const char FF[2][4][5] = 
{
	{"d2d3", "e2e3", "c1d2", "f1e2"},
	{"d7d6", "e7e6", "c8d7", "f8e7"}
};

bool find_some_move(game_move &move)
{
	int x0, x1, x2;
	x0 = 0;
	x1 = 8;
	x2 = 1;
	if (MyColor == 2)
	{
		x0 = 7;
		x1 = -1;
		x2 = -1;
	}
	for (int x = x0; x != x1; x += x2)
	for (int y = 2; y <= 5; y++)
	{
		if (board[x][y] != MyColor) continue;
		for (int k = 0; k < 3; k++)
		{
			move = game_move(x, y, x + MM[MyColor-1][k][0], y + MM[MyColor-1][k][1]);
			if (
				move_is_ok(move)  &&
				board[move.ex][move.ey] == 0 &&
				move.ey >= 3 && 
				move.ey <= 4
			) 
			{
				DD(fprintf(fff, "some move\n");)
				DD(fflush(fff);)
				
				return 1;
			}
		}
	}
	return 0;
}

void find_any_move(game_move &move)
{
	for (int x = 0; x < 8; x++)
	for (int y = 0; y < 8; y++)
	{
		if (board[x][y] != MyColor) continue;
		for (int k = 0; k < 3; k++)
		{
			move = game_move(x, y, x + MM[MyColor-1][k][0], y + MM[MyColor-1][k][1]);
			if (move_is_ok(move) && board[move.ex][move.ey] == 0) return;
		}
	}
	
	DD(fprintf(fff, "any move\n");)
	DD(fflush(fff);)
}

int test[8][8];
game_move mtest[8][8];

bool dfs(int x, int y)
{
	if (test[x][y]) return 0;
	test[x][y] = 1;
	
	if (MyColor == 1 && x == 7) return 1;
	if (MyColor == 2 && x == 0) return 1;
	
	for (int k = 0; k < 3; k++)
	{
		game_move move = game_move(x, y, x + MM[MyColor-1][k][0], y + MM[MyColor-1][k][1]);
		
		game_move c1(move.ex, move.ey, move.ex + MM[MyColor-1][0][0], move.ey + MM[MyColor-1][0][1]);
		game_move c2(move.ex, move.ey, move.ex + MM[MyColor-1][2][0], move.ey + MM[MyColor-1][2][1]);
		
		if (move_is_ok(move) &&	(board[move.ex][move.ey] == 0 || (k != 1 && board[move.ex][move.ey] == op_color(MyColor)))) 
		{
			if (
				(!move_is_ok(c1) || board[c1.ex][c1.ey] != op_color(MyColor)) && 
				(!move_is_ok(c2) || board[c2.ex][c2.ey] != op_color(MyColor)) && 
				dfs(move.ex, move.ey)
				)
			{
				mtest[x][y] = move;
				return 1;
			}
		}
	}
	
	return 0;
}

bool find_forward_move(game_move &move)
{
	for (int x = 0; x < 8; x++)
	for (int y = 0; y < 8; y++)
	{
		if (board[x][y] != MyColor) continue;
		
		if (MyColor == 1 && x < 3) continue;
		if (MyColor == 2 && x > 4) continue;
		
		memset(test, 0, sizeof(test));
		if (dfs(x, y))
		{
			move = mtest[x][y];
			
			DD(fprintf(fff, "forward move\n");)
			DD(fflush(fff);)
			
			return 1;
		}
	}
	return 0;
}

bool find_safe_move(game_move &move)
{
	int x0, x1, x2;
	x0 = 0;
	x1 = 8;
	x2 = 1;
	if (MyColor == 2)
	{
		x0 = 7;
		x1 = -1;
		x2 = -1;
	}
	for (int x = x0; x != x1; x += x2)
	for (int y = 2; y <= 5; y++)
	{
		if (board[x][y] != MyColor) continue;
		for (int k = 0; k < 3; k++)
		{
			move = game_move(x, y, x + MM[MyColor-1][k][0], y + MM[MyColor-1][k][1]);
			
			game_move c1(move.ex, move.ey, move.ex + MM[MyColor-1][0][0], move.ey + MM[MyColor-1][0][1]);
			game_move c2(move.ex, move.ey, move.ex + MM[MyColor-1][2][0], move.ey + MM[MyColor-1][2][1]);
			
			if (
				move_is_ok(move) &&	
				board[move.ex][move.ey] == 0 &&
				move.ey >= 3 && 
				move.ey <= 4
			) 
			if (
				(!move_is_ok(c1) || board[c1.ex][c1.ey] != op_color(MyColor)) && 
				(!move_is_ok(c2) || board[c2.ex][c2.ey] != op_color(MyColor))
				)
			{
				DD(fprintf(fff, "safe move\n");)
				DD(fflush(fff);)
				
				return 1;
			}
		}
	}
	return 0;
}

void think(char *str) 
{
	game_move move;
	if (!find_forward_move(move))
	if (!kill_them_all(move))
	{
		if (CC < 4)
		{
			strcpy(str, FF[MyColor-1][CC++]);
			make_move(str);
			return;
		}
		else
		{
			if (!find_safe_move(move))
			if (!find_some_move(move)) 
				find_any_move(move);
		}
	}
	show_move(str, move);
	make_move(move);
}

int main() {
	DD(fff = fopen("dbg.txt", "w");)
//	srand(time(0));
	init();
	MyColor = BLACK;
	for(;;) {
		char str[100];
		gets(str);
		if(!strcmp(str,"Name")) {
			// Request for the bot name
			string name = "MegBegE aka &ELF-GUHO";
			printf("%s\n", name.c_str());
			fflush(stdout);
		}
		else if(!strcmp(str,"Quit")) {
			// Game is over
			break;
		}
		else {
			if(strcmp(str,"Start") != 0) {
				// Enemy's move
				make_move(str);
			}
			else
				MyColor = WHITE;
			// Our move
			think(str);
			printf("%s\n",str);
			
			DD(fprintf(fff, "%s\n", str);)
			DD(fflush(fff);)
			
			fflush(stdout);
		}
	}
	
	DD(fclose(fff);)
	
	return 0;
}
