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

#include <list>
#include <vector>
#include <string>
#include <map>

using namespace std;

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

FILE* f;

/*#define debug(form, ...) \
	f = fopen("m:\\output.txt", "a"); \
	fprintf(f, form, ## __VA_ARGS__); \
	fclose(f);
	*/

#define  debug(form, ...)

enum {EMPTY = 0,WHITE,BLACK};
int ourColor = BLACK;

 double MAXPRICE = 1e10;
 int LIMIT = 2;

class Cache;

struct Step
{
public:

	Step()
	{
	}

	Step(int x1,int y1, int x2, int y2)
	{
		t = x1 | (y1 << 3) | (x2 << 6) | (y2 << 9);		
	}

	std::string ToString() 
	{
		int x1 = t & 0x7;
		int y1 = (t >> 3) & 0x7;
		int x2 = (t >> 6) & 0x7;
		int y2 = (t >> 9) & 0x7;
		char str[5];
		str[4] = 0;
		if (ourColor == WHITE)
		{
			sprintf(str, "%c%d%c%d",y1+'a',x1+1,y2+'a',x2+1);
		}
		if (ourColor == BLACK)
		{
			sprintf(str, "%c%d%c%d",y1+'a',8 - x1,y2+'a',8 - x2);
		}
		return str;
	}
	
private:
	short int t;
};

struct GameState
{
	__int64 s1;
	__int64 s2;
	bool ourTurn;

	//list<GameState*> children;
	//List<short int> steps;

	/*
	~GameState()
	{
		for(list<GameState>::iterator it = children.begin(); it != MainState.children.end(); it++)
		{
			delete &(*it);
		}
	}
	*/
	
	bool operator<( const GameState& state) const
	{
		return s1 < state.s1 || s1 == state.s1 && s2 < state.s2;
	}

	pair<Step, GameState> Next(int x1,int y1, int x2, int y2) 
	{
		GameState s = *this;
		s.Set(x2,y2,s.Get(x1,y1));
		s.Set(x1,y1,EMPTY);
		s.ourTurn = !ourTurn;
		return make_pair(Step(x1, y1, x2, y2), s);
	}


	short int GetStep(int x1,int y1, int x2, int y2)
	{
		short int t;
		t = x1 | (y1 << 3) | (x2 << 6) | (y2 << 9);
		return t;
	}

	void GetStep(short int step, int& x1, int &y1, int &x2, int &y2)
	{
		x1 = step & 0x7;
		y1 = (step >> 3) & 0x7;
		x2 = (step >> 6) & 0x7;
		y2 = (step >> 9) & 0x7;
	}
/*
	void Refresh(int n)
	{
		if (n & 1)
		{
		}
		else
		{
			for(int i = 0; i < 7; i++)
				for(int j = 0; j < 8; j++)
				{
					if (Get(i,j) == WHITE)
					{
						if (Get(i + 1, j) == EMPTY)
						{
							children.
						}
					}
				}
		}
	}
*/
	int Price() 
	{
		return Price(0);
	}

	bool IsVictori()
	{		
		if (s2 == 0) return true;
		return (s1 & 0xff00000000000000LL) != 0;
	}

	bool IsDefeat()
	{
		if (s1 == 0) return true;
		return (s2 & 0xFFLL) != 0;
	}

	double Price(int n) ;

	void Init()
	{
		s1 = 0;
		s2 = 0;
		ourTurn = true;
		for(int i = 0; i < BOARD_SIZE; i++)
		{
			Set(0,i,WHITE);
			Set(1,i,WHITE);

			Set(6,i,BLACK);
			Set(7,i,BLACK);
		}
	}

	char Get(int x, int y) 
	{
		int num = x * BOARD_SIZE + y;
		if (s1 & (1LL << num) ) return WHITE;
		if (s2 & (1LL << num) ) return BLACK;
		return EMPTY;
	}

	void Set(int x, int y, char value)
	{
		__int64 num = x * BOARD_SIZE + y;
		switch(value)
		{
		case WHITE:
			s1 = s1 | (1LL << num);
			s2 = s2 & ~ ( 1LL << num);
			break;
		case BLACK:
			s1 = s1 & ~ ( 1LL <<  num);
			s2 = s2 | (1LL << num);
			break;
		case EMPTY:
			s1 = s1 & ~ (1LL << num);
			s2 = s2 & ~ (1LL << num);
			break;
		}
	}

};

GameState MainState;

typedef pair<Step, GameState>  CacheEntry;

class Cache
{
public:
	static list<CacheEntry> Children( GameState& state) 
	{
		if (cache.find(state) == cache.end())
		{
			cache[state] = GenerateChildren(state);
		}
		return cache[state];	
	}

	static void ForgetAllExcept( GameState& state)
	{
		cache.clear();
	}

private:

	static list<CacheEntry> GenerateChildren( GameState& state)
	{
		list<CacheEntry> result;
		if (state.ourTurn)
		{
			for(int i = 0; i < 7; i++)
			{
				for(int j = 0; j < 8; j++)
				{
					if (state.Get(i,j) == WHITE)
					{
						if (state.Get(i + 1, j) == EMPTY)
						{							
							result.push_back(state.Next(i ,j, i + 1, j));
						}
						if (j > 0 && state.Get(i + 1, j - 1) != WHITE)
						{
							result.push_back(state.Next(i, j, i + 1, j - 1));
						}
						if (j < 7 && state.Get(i + 1, j + 1) != WHITE)
						{
							result.push_back(state.Next(i, j, i + 1, j + 1));
						}
					}
				}
			}
		}
		else
		{
			for(int i = 1; i < 8; i++)
			{
				for(int j = 0; j < 8; j++)
				{
					if (state.Get(i, j) == BLACK)
					{
						if (state.Get(i - 1, j) == EMPTY)
						{
							result.push_back(state.Next(i ,j, i - 1, j));
						}
						if (j > 0 && state.Get(i - 1, j - 1) != BLACK)
						{
							result.push_back(state.Next(i, j, i - 1, j - 1));
						}
						if (j < 7 && state.Get(i - 1, j + 1) != BLACK)
						{
							result.push_back(state.Next(i, j, i - 1, j + 1));
						}
					}
				}
			}
		}
		return result;
	}

	static map<GameState, list<CacheEntry> > cache;
};

map<GameState, list<CacheEntry> > Cache::cache;

double GameState::Price(int n) 
{
	if (IsVictori()) 
	{
		debug("IsVictory!\n");
		return MAXPRICE / n;
	}
	if (IsDefeat()) return -MAXPRICE;

	//if (LIMIT != n) Refresh();

	if (n == LIMIT)
	{
		int minDist1 = 8;
		int minDist2 = 8;
		int n1 = 0;
		int n2 = 0;

		for(int i = 0; i < 8; i++)
			for(int j = 0; j < 8; j++)
			{
				char t = Get(i,j);
				if (t == WHITE) 
				{
					if (7 - i < minDist1) minDist1 = 7 - i;
					n1 ++;
				}
				if (t == BLACK)
				{
					if (i < minDist2) minDist2 = i;
					n2 ++;
				}
			}

		double Kd1 = 1.0;
		double Kd2 = 1.0;
		double Kn1 = 1.0;
		double Kn2 = 1.0;

		return Kd1 * ( 7 - minDist1) - Kd2*(7 - minDist2) + Kn1 * n1 - Kn2 * n;
	}
	else
	{
		double minP = MAXPRICE * 10;
		double maxP = - MAXPRICE * 10;

		list<CacheEntry>& children = Cache::Children(*this);

		for(list<CacheEntry>::iterator it = children.begin(); it != children.end(); it++)
		{
			double price = (it->second).Price(n + 1);
			if (price < minP) minP = price;
			if (price > maxP) maxP = price;
		}

		if (n & 1)
		{
			return minP;
		}
		else
		{
			return maxP;
		}
	}
}

void print( Step& step)
{	
	debug("%s\n", step.ToString().c_str());
	printf("%s\n", step.ToString().c_str());
	fflush(stdout);
}




void read(char * str, int &x1, int &y1, int&x2, int &y2)
{
	if (ourColor == WHITE)
	{
		  char sy,ey;
		  int sx,ex;	
		  sscanf(str,"%c%d%c%d",&sy,&sx,&ey,&ex);
		  x1 = sx - 1;
		  x2 = ex - 1;
		  y1 = sy - 'a';
		  y2 = ey - 'a';
	}
	if (ourColor == BLACK)
	{
		  char sy,ey;
		  int sx,ex;	
		  sscanf(str,"%c%d%c%d",&sy,&sx,&ey,&ex);
		  x1 = 8 - sx;
		  x2 = 8 - ex;
		  y1 = sy - 'a';
		  y2 = ey - 'a';
	}
}

void init() 
{
	MainState.Init();
}


void make_move()
{
	Cache::ForgetAllExcept(MainState);
	double bestPrice = -MAXPRICE* 10 ;
	 list<CacheEntry>& children = Cache::Children(MainState);
	vector<CacheEntry> best;
	for(list<CacheEntry>::iterator it = children.begin(); it != children.end(); it++)
	{
		double price = it->second.Price();
		//printf("Step: %s, Price: %lf\n", it->first.ToString().c_str(), price);
		if (it->second.IsVictori())
		{
			best.resize(0);
			bestPrice = price;
			best.push_back(*it);
			break;
		}
		if (price > bestPrice)
		{
			best.resize(0);
			bestPrice = price;
			best.push_back(*it);
		}
		else
		{
			if (price == bestPrice)
			{
				best.push_back(*it);
			}
		}		
	}
	int num = rand() % best.size();
	print(best[num].first);
	MainState = best[num].second;	
	/*

	int x1,y1,x2,y2;
	MainState.Refresh();

	vector<short int> best;
	double bestPrice = -MAXPRICE* 10 ;
	int i = 0;
	list<short int>::iterator iStep = MainState.steps.begin();

	for(list<GameState>::iterator it = MainState.children.begin(); it != MainState.children.end(); it++)
	{
		double price = it->Price();
		if (price > bestPrice)
		{
			best.resize(0);
			bestPrice = best;
			best.push_back(*iStep);
		}
		else
		{
			if (price == bestPrice)
			{
				best.push_back(*iStep);
			}
		}
		iStep++;
	}

	int num = rand() % best.size();
	MainState.GetStep(best[num],x1,y1,x2,y2);
	print(x1,y1,x2,y2);*/
}

void think(char *str) 
{
	int x1,x2,y1,y2;
	read(str,x1,y1,x2,y2);
	//обработываем состояние
	MainState.Set(x1,y1,EMPTY);
	MainState.Set(x2,y2,BLACK);
	MainState.ourTurn = !MainState.ourTurn;
	make_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 main() {
  //srand(time(0));
  init();
  for(;;) {
    char str[100];
    gets(str);
    if(!strcmp(str,"Name")) {
      // Request for the bot name
      printf("SUrSU x92\n");
      fflush(stdout);
    }
    else if(!strcmp(str,"Quit")) {
      // Game is over
      break;
    }
    else 
	{
      if(!strcmp(str,"Start")) {
        ourColor = WHITE;
        make_move();
      }
	  else
	  {
      // Our move
		think(str);
	  }
//    printf("%s\n",str);
//    fflush(stdout);
    }
  }
  return 0;
}


