/*------------------------------------------------------------
TEAM48
A
236
Target: MSVC9; Platform: Win32; Comment: MS Visual C++ 9
------------------------------------------------------------*/
// Cry bot for "Breakthrough" game
// Ural Championship 2010 Game Tour
// Author: r57shell

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <cstring>
#include <time.h>
#include <algorithm>
#include <queue>
#include <vector>

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

enum {EMPTY,WHITE,BLACK};

char board[BOARD_SIZE][BOARD_SIZE];
char board_return_of_the_king[BOARD_SIZE][BOARD_SIZE]; //board 2:expansion; //cheat: open console enter "ololo" - god mode;
char attack[BOARD_SIZE][BOARD_SIZE];
int color;

struct game_move {
	int sx,sy;
	int ex,ey;
	int is_capture;
	bool operator <(const game_move & a) const
	{
		if(is_capture!=a.is_capture)
			return is_capture>a.is_capture;
		if (!((attack[  ex][  ey]&&
			   attack[a.ex][a.ey])
			||
			(!attack[  ex][  ey]&&
			 !attack[a.ex][a.ey])))
			return (!attack[  ex][  ey]
				   &&attack[a.ex][a.ey]);
		if (ex>sx)
		{
		if (sx!=a.sx)
			return sx<a.sx;
		if (sy!=a.sy)
			return sy<a.sy;
		if (ex!=a.ex)
			return ex<a.ex;
		if (ey!=a.ey)
			return ey<a.ey;
		return is_capture<a.is_capture;
		}
		else
		{
		if (sx!=a.sx)
			return sx>a.sx;
		if (sy!=a.sy)
			return sy<a.sy;
		if (ex!=a.ex)
			return ex>a.ex;
		if (ey!=a.ey)
			return ey<a.ey;
		}
	}
};

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

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;
}

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;
}

game_move plan;
int escape_time;
//int xz;

bool escape(int x,int y);

void think(char *str) {
	game_move moves[MAX_MOVES];
	int cnt=gen_moves(moves);
	/*if (xz==26)
		xz=xz;*/
	memset(board_return_of_the_king,EMPTY,sizeof(board_return_of_the_king));
	memset(attack,EMPTY,sizeof(attack));
	std::queue<int> q;
	for(int i=0;i<BOARD_SIZE;++i)
	{
		for(int j=0;j<BOARD_SIZE;++j)
		{
			if(board[i][j]==(3-color))
			{
				q.push((i<<3)|j);
				board_return_of_the_king[i][j]=1;
#define OLOLO1(x,y) \
				if(i+x>=0&&i+x<BOARD_SIZE \
				&&j+y>=0&&j+y<BOARD_SIZE) \
				{ \
					attack[i+x][j+y]=1; \
				}
				if (color==WHITE)
				{
					OLOLO1(-1,-1);
					OLOLO1(-1,1);
				}
				else
				{
					OLOLO1(1,-1);
					OLOLO1(1,1);
				}
			}
		}
	}
	int i,j;
#define b board_return_of_the_king
	while(!q.empty())
	{
		i=q.front()>>3;
		j=q.front()&7;
		q.pop();
#define OLOLO(x,y) \
		if(i+x>=0&&i+x<BOARD_SIZE \
		&&j+y>=0&&j+y<BOARD_SIZE \
		&&(!b[i+x][j+y]||b[i+x][j+y]>b[i][j]+1)) \
		{ \
			b[i+x][j+y]=b[i][j]+1; \
			q.push(((i+x)<<3)|(j+y)); \
		}
		if (color!=WHITE)
		{
			OLOLO(1,-1);
			OLOLO(1, 0);
			OLOLO(1, 1);
		}
		else
		{
			OLOLO(-1,-1);
			OLOLO(-1, 0);
			OLOLO(-1, 1);
		}
	}
	std::sort(moves,moves+cnt);
	game_move &move=moves[0];//moves[rand()%cnt];
	if (!move.is_capture)
	{
		bool RUN_STUB_RUN=false;
		for(int i=(color==WHITE?BOARD_SIZE-1:0);(color==WHITE?(i>=0):(i<BOARD_SIZE));i+=(color==WHITE?-1:1))
		{
			for(int j=0;j<BOARD_SIZE;++j)
			{
				if(board[i][j]==color)
				{
					escape_time=0;
					plan.sx=i;
					plan.sy=j;
					if (escape(i,j))
					{
						RUN_STUB_RUN=true;
						break;
					}
				}
			}
			if (RUN_STUB_RUN)
				break;
		}
		if (RUN_STUB_RUN)
		{
			move=plan;
			/*FILE *out=fopen("asdasd.txt","a");
			for (int i=BOARD_SIZE-1;i>=0;--i)
			{
				for (int j=0;j<BOARD_SIZE;++j)
					putc('0'+board[i][j],out);
				putc('\n',out);
			}
			putc('\n',out);
			for (int i=BOARD_SIZE-1;i>=0;--i)
			{
				for (int j=0;j<BOARD_SIZE;++j)
					putc('0'+board_return_of_the_king[i][j],out);
				putc('\n',out);
			}
			fprintf(out,"%d %c%d%c%d\n",xz,move.sy+'a',move.sx+1,move.ey+'a',move.ex+1);
			fflush(out);
			fclose(out);*/
		}
	}
no_escape:
	sprintf(str,"%c%d%c%d",move.sy+'a',move.sx+1,move.ey+'a',move.ex+1);
	make_move(move);
}
#undef OLOLO

bool escape(int x,int y)
{
	if (escape_time==1)
	{
		plan.ex=x;
		plan.ey=y;
	}
	if ((color==WHITE&&x==7)
	  ||(color==BLACK&&x==0))
		return true;
	++escape_time;
#define OLOLO(i,j) \
	if(i+x>=0&&i+x<BOARD_SIZE \
	&&j+y>=0&&j+y<BOARD_SIZE \
	&&board[i+x][j+y]==EMPTY \
	&& \
	( \
		!b[i+x][j+y] \
		|| \
		b[i+x][j+y]>escape_time+1 \
		) \
	) \
	{ \
		if (escape(i+x,j+y)) \
		{ \
			--escape_time; \
			return true; \
		} \
	}
	if (color==WHITE)
	{
		OLOLO(1,-1);
		OLOLO(1, 0);
		OLOLO(1, 1);
	}
	else
	{
		OLOLO(-1,-1);
		OLOLO(-1, 0);
		OLOLO(-1, 1);
	}
	--escape_time;
	return false;
}
#undef b
#undef OLOLO

int main() {
  //freopen("asd.in","r",stdin);
  srand(time(0));
  init();
  for(;;) {
    char str[100];
    gets(str);
    if(!strcmp(str,"Name")) {
      // Request for the bot name
      printf("StubMayCry v7\n");
      fflush(stdout);
    }
    else if(!strcmp(str,"Quit")) {
      // Game is over
      break;
    }
    else {
      if(strcmp(str,"Start")) {
        // Enemy's move
		// Cry :_(
        make_move(str);
      }
//	  ++xz;
      // Our move
	  // For Aiur!
      think(str);
      printf("%s\n",str);
      fflush(stdout);
    }
  }
  return 0;
}
