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

using namespace std;

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

enum {EMPTY,WHITE,BLACK};

struct game_move {
  int sx,sy;
  int ex,ey;
  int is_capture;
};

/*struct tree {
	game_move move;
	tree *root;
	tree **tree;
}*/

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

char board[BOARD_SIZE][BOARD_SIZE];
int color;
int step;

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;
  }
  color=WHITE;
  step = 0;
}

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

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',board[ex-1][ey-'a']!=EMPTY};
  make_move(move);
}

int gen_moves(game_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 dj=-1;dj<=1;++dj) {
          int ni=i+(color==WHITE ? 1 : -1);
          int nj=j+dj;
          if(ni>=0 && ni<BOARD_SIZE && nj>=0 && nj<BOARD_SIZE &&
             board[ni][nj]!=color && (dj || board[ni][nj]==EMPTY)) {
            game_move move={i,j,ni,nj,board[ni][nj]!=EMPTY};
            moves[cnt++]=move;
          }
        }
      }
    }
  }
  return cnt;
}

void invert ()
{
	int a, i, j;
	for (i = 0; i < 4; ++i)
	{
		for (j = 0; j < 8; ++j)
		{
			a = board[i][j];
			board[i][j] = board[BOARD_SIZE - i - 1][BOARD_SIZE - j - 1];
			board[BOARD_SIZE - i - 1][BOARD_SIZE - j - 1] = a;
		}
	}
}

void invert_turn (game_move &move)
{
	move.ex = BOARD_SIZE - move.ex - 1;
	move.ey = BOARD_SIZE - move.ey - 1;
	move.sx = BOARD_SIZE - move.sx - 1;
	move.sy = BOARD_SIZE - move.sy - 1;
}

int get_warning1 (game_move &move)
{
	int warning (0);
	int i, j;
	int n = 1;
	if (move.ey - n < 0)
	{
		i = 0;
	}
	else
	{
		i = move.ey - n;
	}
	j = move.ex - n;

	for (; i < move.ey + n && i < BOARD_SIZE - 1; ++i)
	{
		if (i != move.sy && j != move.sy && j >= 0)
		{
			if (board[i][j] == color)
				++warning;
		}
	}
	j = move.ex + n;
	for (; i < move.ey + n && i < BOARD_SIZE - 1; ++i)
	{
		if (j < BOARD_SIZE)
		{
			if (board[i][j] == op_color(color))
				--warning;
		}
	}
	return warning;
}

int get_warning2 (game_move &move)
{
	int warning (0);
	int i, j;
	int n = 2;
	if (move.ey - n < 0)
	{
		i = 0;
	}
	else
	{
		i = move.ey - n;
	}
	j = move.ex - n;

	for (; i < move.ey + n && i < BOARD_SIZE - 1; ++i)
	{
		if (j >= 0)
		{
			if (board[i][j] == color)
				++warning;
		}
	}
	j = move.ex + n;
	for (; i < move.ey + n && i < BOARD_SIZE - 1; ++i)
	{
		if (j < BOARD_SIZE)
		{
			if (board[i][j] == op_color(color))
				--warning;
		}
	}
	return warning;
}

int get_warning3 (game_move &move)
{
	int i, j;
	int warning (0);
	int n = 3;
	if (move.ey - n < 0)
	{
		i = 0;
	}
	else
	{
		i = move.ey - n;
	}
	j = move.ex - n;

	for (; i < move.ey + n && i < BOARD_SIZE - 1; ++i)
	{
		if (j >= 0)
		{
			if (board[i][j] == color)
				++warning;
		}
	}

	j = move.ex + n;
	for (; i < move.ey + n && i < BOARD_SIZE - 1; ++i)
	{
		if (j < BOARD_SIZE)
		{
			if (board[i][j] == op_color(color))
				--warning;
		}
	}
	return warning;
}


void turn (char *str)
{
	int i, j;
	int de = rand () % 2;
	game_move move;
	game_move moves[MAX_MOVES];
	int count;
	int warning1 [MAX_MOVES];
	int warning2 [MAX_MOVES];
	int warning3 [MAX_MOVES];
	int warning;
	list<int> list_turn2;
	list<int> list_turn3;
	list<int>::iterator iter;
	count = gen_moves (moves);

	bool find_turn (false);

	if (color == BLACK)
	{
		invert ();
		for (i = 0; i < count; ++i)
		{
			invert_turn (moves[i]);
		}
	}
	if (step == 0)
	{
		move.sx = 1;
		move.sy = 3;
		move.ex = 2;
		move.ey = 4;
	}
	else
	{
		for (i = 0; i < count; ++i)
		{
			warning1[i] = get_warning1 (moves[i]);
			warning2[i] = get_warning2 (moves[i]);
			warning3[i] = get_warning3 (moves[i]);
		}
		
		for (i = 0; i < count; ++i)
		{
			if (warning1[i] > 0)
			{
				list_turn2.push_back(i);
			}
		}

		for (iter = list_turn2.begin (); iter != list_turn2.end (); ++iter)
		{
			if (warning2[*iter] < 0)
			{
				list_turn2.remove (*iter);
			}
		}

		for (iter = list_turn2.begin (); iter != list_turn2.end (); ++iter)
		{
			if (warning3[*iter] < 0)
			{
				list_turn2.remove (*iter);
			}
		}

		warning = warning1[list_turn2.front ()] + warning2[list_turn2.front ()] + warning3[list_turn2.front ()];
		for (iter = list_turn2.begin (); iter != list_turn2.end (); ++iter)
		{
			if (warning < warning1[*iter] + warning2[*iter] + warning3[*iter])
			{
				warning = warning1[*iter] + warning2[*iter] + warning3[*iter];
			}
		}
		for (iter = list_turn2.begin (); iter != list_turn2.end (); ++iter)
		{
			if (warning == warning1[*iter] + warning2[*iter] + warning3[*iter])
			{
				i = *iter;
				break;
			}
		}

		if (list_turn2.empty ())
		{
			i = rand() % count;
		}
		
		move = moves[i];
	}

	if(color == BLACK)
	{
		invert_turn (move);
		invert ();
	}
	make_move (move);
	sprintf(str,"%c%d%c%d",move.sy+'a',move.sx+1,move.ey+'a',move.ex+1);
}

void think(char *str) {
  //game_move moves[MAX_MOVES];
  //int cnt=gen_moves(moves);

  turn (str);
}

int main() {
  srand(time(0));
  init();
  for(;;) {
    char str[100];
    gets(str);
    if(!strcmp(str,"Name")) {
      // Request for the bot name
	  printf("Chess Line\n");
      fflush(stdout);
    }
    else if(!strcmp(str,"Quit")) {
      // Game is over
      break;
    }
    else {
      if(strcmp(str,"Start")) {
        // Enemy's move
        make_move(str);
      }
      // Our move
      think(str);
      printf("%s\n",str);
	  ++step;
      fflush(stdout);
    }
  }
  return 0;
}
