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

using namespace std;

typedef  char u8;
typedef unsigned long long u64;

#define CLR(a, b) memset(a, b, sizeof(a))


#define inf 1000000000
#define inf2 (inf-1000)

//#define LOG

struct state
{
	int wh;
	int gover;
	u64 white, black;
};

struct move
{
	u8 src;
	u8 dst;
	bool capt;
	bool r;
	int val;
	void print()
	{
		printf("%c%d%c%d\n",src%8+'a',src/8+1,dst%8+'a',dst/8+1);
	}
	friend bool operator < (const move &u, const move &v)
	{
		return u.val > v.val;
	}
};

struct movelist
{
	move m[48];
	int n;
};

inline int cnt(u64 mask)
{
	int res = 0;
	for (int i = 0; i < 64; i++)
		if (mask & (1ull << i))
			res++;
	return res;
}

int mat(const state &st)
{
	if (st.wh)
		return cnt(st.white) - cnt(st.black);
	else
		return cnt(st.black) - cnt(st.white);
}

//int mindist(const state &st)
//{
//	if (st.wh)
//	{
//		int q = 0;
//		for (int i = 0; i < 64; i++)
//			if (st.white & (1ull << i))
//				q = i;
//		return 7 - q / 8;
//	}
//	else
//	{
//		int q = 0;
//		for (int i = 0; i < 64; i++)
//			if (st.black & (1ull << i))
//			{
//				q = i;
//				break;
//			}
//		return q / 8;
//	}
//}
//
//int mindist_en(const state &st)
//{
//	if (!st.wh)
//	{
//		int q = 0;
//		for (int i = 0; i < 64; i++)
//			if (st.white & (1ull << i))
//				q = i;
//		return 7 - q / 8;
//	}
//	else
//	{
//		int q = 0;
//		for (int i = 0; i < 64; i++)
//			if (st.black & (1ull << i))
//			{
//				q = i;
//				break;
//			}
//		return q / 8;
//	}
//}

int calc_wh(const state &st, int p)
{
	int res = 0;
	for (int i = 0; i < 64; i++)
		if (st.black & (1ull << i))
		{
			int dx = abs(p % 8 - i % 8);
			int dy = i / 8 -  p / 8;
			if (dy >= dx) res++;
		}
	return res;
}

int calc_bl(const state &st, int p)
{
	int res = 0;
	for (int i = 0; i < 64; i++)
		if (st.white & (1ull << i))
		{
			int dx = abs(p % 8 - i % 8);
			int dy = - i / 8 +  p / 8;
			if (dy >= dx) res++;
		}
	return res;
}

int _eval(const state &st)
{
	int res = 0;
	if (st.wh)
	{
		for (int i = 0; i < 64; i++)
			if (st.white & (1ull << i))
			{
				int t = calc_wh(st, i);
				res += 10000 / (1 + t);
			}
	}
	else
	{
		for (int i = 0; i < 64; i++)
			if (st.black & (1ull << i))
			{
				int t = calc_bl(st, i);
				res += 10000 / (1 + t);
			}
	}
	return res;
}

int eval(const state &st)
{
	if (st.gover)
		return -inf;
	int res = 0;
	res += _eval(st);
	state st2 = st;
	st2.wh = 1 - st2.wh;
	res -= _eval(st2);

	/*res += 1000 * mat(st);
	int dist_my = mindist(st);
	int dist_en = mindist_en(st);
	res += (dist_en - dist_my) * 2000;*/
	return res;
}

state st;

u8 mwh1[64], mwh2[64], mwh3[64];
u8 mbl1[64], mbl2[64], mbl3[64];

void init()
{
	st.gover = 0;
	st.wh = 1;
	st.black = 0;
	st.white = 0;
	for (int i = 0; i < 16; i++) st.white |= 1ull << i;
	for (int i = 48; i < 64; i++) st.black |= 1ull << i;

	CLR(mwh1, -1);
	CLR(mwh2, -1);
	CLR(mwh3, -1);
	for (int i = 0; i < 64; i++)
	{
		if (i + 8 < 64)
		{
			mwh1[i] = i+8;
			if (i % 8 != 0) mwh2[i] = i+7;
			if (i % 8 != 7) mwh3[i] = i+9;
		}
	}

	CLR(mbl1, -1);
	CLR(mbl2, -1);
	CLR(mbl3, -1);
	for (int i = 0; i < 64; i++)
	{
		if (i - 8 >= 0)
		{
			mbl1[i] = i-8;
			if (i % 8 != 0) mbl2[i] = i-9;
			if (i % 8 != 7) mbl3[i] = i-7;
		}
	}
}

inline void add(movelist &list, u8 src, u8 dst, bool capt)
{
	list.m[list.n].src = src;
	list.m[list.n].dst = dst;
	list.m[list.n].capt = capt;
	list.n++;
}

void gen(state st, movelist &list)
{
	list.n = 0;
	if (st.gover)
		return;
	if (st.wh)
	{
		for (int i = 0; i < 64; i++) if ((1ull << i) & st.white)
		{
			if (mwh1[i] != -1 && (st.black & (1ull << mwh1[i])) == 0 && (st.white & (1ull << mwh1[i])) == 0)
				add(list, i, mwh1[i], false);
			if (mwh2[i] != -1 && (st.white & (1ull << mwh2[i])) == 0)
			{
				add(list, i, mwh2[i],  (st.black & (1ull << mwh2[i])) != 0);
			}
			if (mwh3[i] != -1 && (st.white & (1ull << mwh3[i])) == 0)
			{
				add(list, i, mwh3[i], (st.black & (1ull << mwh3[i])) != 0);
			}
		}
	}
	else
	{
		for (int i = 0; i < 64; i++) if ((1ull << i) & st.black)
		{
			if (mbl1[i] != -1 && (st.white & (1ull << mbl1[i])) == 0 && (st.black & (1ull << mbl1[i])) == 0)
				add(list, i, mbl1[i], false);
			if (mbl2[i] != -1 && (st.black & (1ull << mbl2[i])) == 0)
			{
				add(list, i, mbl2[i], (st.white & (1ull << mbl1[i])) != 0);
			}
			if (mbl3[i] != -1 && (st.black & (1ull << mbl3[i])) == 0)
			{
				add(list, i, mbl3[i], (st.white & (1ull << mbl1[i])) != 0);
			}
		}
	}
}

state make(const state &st, move m)
{
	state res = st;
	if (st.wh)
	{
		res.white ^= 1ull << m.src;
		res.white ^= 1ull << m.dst;
		res.black &= ~(1ull << m.dst);
		if (m.dst > 56)
			res.gover = 1;
	}
	else
	{
		res.black ^= 1ull << m.src;
		res.black ^= 1ull << m.dst;
		res.white &= ~(1ull << m.dst);
		if (m.dst < 8)
			res.gover = 1;
	}
	res.wh = 1 - res.wh;
	return res;
}

u8 fromxy(int x, int y)
{
	return x*8 + y;
}

void make_move(char *str) {
  char sy,ey;
  int sx,ex;
  sscanf(str,"%c%d%c%d",&sy,&sx,&ey,&ex);
  move m;
  m.src = fromxy(sx - 1, sy - 'a');
  m.dst = fromxy(ex - 1, ey - 'a');
  st = make(st, m);
}

int itcnt;
clock_t start;
bool stop;

int max_depth;

int go(state st, move &bestm, int depth, int alpha, int beta, int depth2, int real_depth)
{
	if (real_depth > max_depth)
		max_depth = real_depth;
	if (stop)
	{
		return 0;
	}
	else
	{
		itcnt++;
		if (itcnt % 100 == 0)
		{
			if (clock() > start + 2750)
				stop = true;
		}
	}
	movelist list;
	gen(st, list);
	int n = list.n;
	if (n == 0)
	{
		return -inf;
	}
	for (int i = 0; i < n; i++)
	{
		state st2 = make(st, list.m[i]);
		list.m[i].val = -eval(st2);
	}
	sort(list.m, list.m+n);
	if (depth == 0)
	{
		bestm = list.m[0];
		return list.m[0].val;
	}
	int best = -inf;
	for (int i = 0; i < n; i++)
	{
		state st2 = make(st, list.m[i]);
		move mm;
		int t;
		if (list.m[i].capt && depth2 > 0)
			t = -go(st2, mm, depth, -beta, -alpha, depth2 - 1, real_depth + 1);
		else
			t = -go(st2, mm, depth - 1, -beta, -alpha, depth2, real_depth + 1);

		if (t > inf2)
			t--;
		if (t < -inf2)
			t++;
		alpha = max(alpha, t);
		if (t > best)
		{
			best = t;
			bestm = list.m[i];
		}
		if (alpha >= beta)
			break;
	}
	return best;
}
#ifdef LOG
	FILE *f;
#endif

void think(char *str) {
	//movelist list;
	//gen(st, list);
	////for (int i = 0; i < list.n; i++)
	////	list.m[i].print();
	//move m = list.m[rand()%list.n];

	start = clock();
	itcnt = 0;
	stop = false;
	move m;
	int val;
	int depth;
	max_depth = 0;
	for (depth = 1; !stop; ++depth)
	{
		move m_loc;
		int x = go(st, m_loc, depth, -inf, inf, 3 * depth / 2, 0);
		if (!stop)
		{
			val = x;
			m = m_loc;
		}
	}

	m.print();
	st = make(st, m);
#ifdef LOG
	fprintf(f, "itcnt = %d, val = %d, depth = %d, max = %d\n", itcnt, val, depth, max_depth);
	fflush(f);
#endif
}

int main()
{
#ifdef LOG
	f = fopen("log4.txt", "wt");
#endif
	srand(1313);
	init();
	for(;;) {
		char str[100];
		gets(str);
		if(!strcmp(str,"Name")) {		  
		  printf("TeamSonic FTW!\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);		  
		  fflush(stdout);
		}
	}
	return 0;
}
