/*------------------------------------------------------------
TEAM08
A
174
Target: MSVC9; Platform: Win32; Comment: MS Visual C++ 9
------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <algorithm>
#include <vector>
#include <set>
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 Point {
	int x, y;
	Point(int x = 0, int y = 0): x(x), y(y) {};
};

inline bool operator < (const Point& a, const Point& b) {
	return a.x < b.x || (a.x == b.x && a.y < b.y);
}

typedef vector<Point> Vp;
typedef set<Point> Sp;

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

char board[BOARD_SIZE][BOARD_SIZE];
int color, mvC, enemyMvC;
game_move moves[MAX_MOVES];
game_move enemyMoves[MAX_MOVES];
Vp our, enemy;
Sp weCanKill, enemyCanKill;

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

int gen_enemy_moves(game_move *moves) {
  int cnt=0;
  int col = op_color(color); 
  for(int i=0;i<BOARD_SIZE;++i) {
    for(int j=0;j<BOARD_SIZE;++j) {
      if(board[i][j]==col) {
        for(int dj=-1;dj<=1;++dj) {
          int ni=i+(col==WHITE ? 1 : -1);
          int nj=j+dj;
          if(ni>=0 && ni<BOARD_SIZE && nj>=0 && nj<BOARD_SIZE &&
             board[ni][nj]!=col && (dj || board[ni][nj]==EMPTY)) {
            game_move move={i,j,ni,nj,board[ni][nj]!=EMPTY};
            moves[cnt++]=move;
          }
        }
      }
    }
  }
  return cnt;
}

void enemyCount() {
	enemy.clear();
	  for(int i=0;i<BOARD_SIZE;++i) {
		for(int j=0;j<BOARD_SIZE;++j) {
		  if(board[i][j]==op_color(color)) {
			  enemy.push_back(Point(i, j));
		  }
		}
	  }
}

void ourCount() {
	our.clear();
	  for(int i=0;i<BOARD_SIZE;++i) {
		for(int j=0;j<BOARD_SIZE;++j) {
		  if(board[i][j]==color) {
			  our.push_back(Point(i, j));
		  }
		}
	  }
}

void calcWeCanKill() {
	weCanKill.clear();
	for (int i = 0; i < mvC; ++i) {
		game_move move = moves[i];
		if (move.is_capture) {
			weCanKill.insert(Point(move.ex, move.ey));
		}
	}
}

void calcEnemyCanKill() {
	enemyCanKill.clear();
	for (int i = 0; i < enemyMvC; ++i) {
		game_move move = enemyMoves[i];
		if (move.is_capture) {
			enemyCanKill.insert(Point(move.ex, move.ey));
		}
	}
}

Point calcDangerousEnemyPeshka() {
	Point ret(-1, -1);
	for (int i = 0; i < enemyMvC; ++i) {
		game_move move = enemyMoves[i];
		if (move.is_capture) {
			if (color == WHITE) {
				if (weCanKill.count(Point(move.sx, move.sy)) && (ret.x == -1 || move.ex < ret.x)) {
					ret = Point(move.sx, move.sy);
				}
			} else {
				if (weCanKill.count(Point(move.sx, move.sy)) && (ret.x == -1 || move.ex > ret.x)) {
					ret = Point(move.sx, move.sy);
				}
			}
		}
	}
	return ret;
}

game_move calcSafeMove() {
	for (int i = 0; i < mvC; ++i) {
		game_move move = moves[i];
		bool ok = 1;
		for (int j = 0; j < enemy.size(); ++j) {
			int nx = color == WHITE ? enemy[j].x - 1 : enemy[j].x + 1;
			int ny1 = enemy[j].y  - 1;
			int ny2 = enemy[j].y  + 1;
			if (move.ex == nx && (move.ey == ny1 || move.ey == ny2)) {
				ok = 0;
				break;
			}
		}
		if (ok) {
			return move;
		}
	}
	game_move move={-1,-1,-1,-1,-1};
	return move;
}

void think(char *str) {
  mvC=gen_moves(moves);
  enemyMvC = gen_enemy_moves(enemyMoves);
	ourCount();
	enemyCount();
  calcWeCanKill();
	calcEnemyCanKill();

  //game_move &move=moves[rand()%cnt];
  bool ok = 0;
  game_move opt;
  for (int i = 0; i < mvC; ++i) {
	game_move move = moves[i];
	if (color == WHITE) {
		if (move.ex == 7) {
			opt = move;
			ok = 1;
			break;
		}
	} else {
		if (move.ex == 0) {
			opt = move;
			ok = 1;
			break;
		}
	}
  }
  if (!ok) {
	Point dang = calcDangerousEnemyPeshka();
	if (dang.x != -1) {
		for (int i = 0; i < mvC; ++i) {
			game_move move = moves[i];
			if (move.ex == dang.x && move.ey == dang.y) {
				opt = move;
				ok = 1;
			}
		}
	} else {
		opt = calcSafeMove();
		if (opt.ex == -1)
			opt=moves[rand()%mvC];
		ok = 1;
	}
  }

  sprintf(str,"%c%d%c%d",opt.sy+'a',opt.sx+1,opt.ey+'a',opt.ex+1);
  make_move(opt);
}

int main() {
  //srand(time(0));
  init();
  for(;;) {
    char str[100];
    gets(str);
    if(!strcmp(str,"Name")) {
      // Request for the bot name
      printf("TEAM08\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);
      fflush(stdout);
    }
  }
  return 0;
}
