/*------------------------------------------------------------
TEAM51
A
217
Target: MSVC9; Platform: Win32; Comment: MS Visual C++ 9
------------------------------------------------------------*/
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cmath>
#include <queue>
#include <algorithm>
using namespace std;

template <typename T>
T sqr(T t)
{
	return t*t;
}

template <typename T>
T sign(T t)
{
	return t > 0 ? 1 : t < 0 ? -1 : 0;
}

const int size=8;

struct Board
{
	char board[size][size+1];
	char canFlag[size][size];
	char backFlag[size][size];
	char enemyFlag[size][size];

	Board()
	{
		for(int i=0;i<size;++i)
			board[i][size]=0;
	}

	char* operator[](int i)
	{
		return board[i];
	}

	const char* operator[](int i) const
	{
		return board[i];
	}

	void makeMove(int si,int sj,int ei,int ej)
	{
		board[ei][ej]=board[si][sj];
		board[si][sj]=' ';
	}

	bool canMove(int si,int sj,int di,int dj,char color) const
	{
		return board[si+di][sj+dj]==' ' || board[si+di][sj+dj]!=color && dj!=0;
	}

	void calculateFlags(char color,int dir,int ourLine)
	{
		for(int i=0;i<size;++i)
			fill(canFlag[i],canFlag[i]+size,1);
		for(int i=0;i<size;++i)
			for(int j=0;j<size;++j)
			{
				if(board[i][j]==color)
					if(i+dir>=0 && i+dir<size)
						for(int k=-1;k<=1;k+=2)
							if(j+k>=0 && j+k<size)
								canFlag[i+dir][j+k]=0;
				if(board[i][j]!=' ')
					canFlag[i][j]=0;
			}

		int enemyLine=size-1-ourLine;

		{
			for(int i=0;i<size;++i)
				fill(backFlag[i],backFlag[i]+size,0);
			queue<pair<int,int> > q;
			for(int j=0;j<size;++j)
				if(canFlag[ourLine][j])
				{
					backFlag[ourLine][j]=1;
					q.push(make_pair(ourLine,j));
				}
			while(!q.empty())
			{
				pair<int,int> p=q.front();
				q.pop();
				int i=p.first;
				int j=p.second;
				if(i+dir>=0 && i+dir<size)
					for(int k=-1;k<=1;++k)
						if(j+k>=0 && j+k<size)
							if(canFlag[i+dir][j+k] && !backFlag[i+dir][j+k])
							{
								backFlag[i+dir][j+k]=1;
								q.push(make_pair(i+dir,j+k));
							}
			}
		}

		{
			for(int i=0;i<size;++i)
				fill(enemyFlag[i],enemyFlag[i]+size,0);
			queue<pair<int,int> > q;
			for(int i=0;i<size;++i)
				for(int j=0;j<size;++j)
					if(board[i][j]!=' ' && board[i][j]!=color)
					{
						enemyFlag[i][j]=1;
						q.push(make_pair(i,j));
					}
			while(!q.empty())
			{
				pair<int,int> p=q.front();
				q.pop();
				int i=p.first;
				int j=p.second;
				if(i-dir>=0 && i-dir<size)
					for(int k=-1;k<=1;++k)
						if(j+k>=0 && j+k<size)
							if(canFlag[i-dir][j+k] && !enemyFlag[i-dir][j+k])
							{
								enemyFlag[i-dir][j+k]=1;
								q.push(make_pair(i-dir,j+k));
							}
			}
		}
	}

	double defence(char color,int dir,int ourLine)
	{
		const double defenceCoef = 4;
		const double attackCoef = 2;
		const double generalCoef = 2;
		const double lifeCoef = 0.1;

		calculateFlags(color,dir,ourLine);

		double r=0;
		for(int i=0;i<size;++i)
			for(int j=0;j<size;++j)
				if(board[i][j]==color)
				{
					int count=0;
					if(i-dir>=0 && i-dir<size)
						for(int k=-1;k<=1;k+=2)
							if(j+k>=0 && j+k<size)
								if(board[i-dir][j+k]==color)
									count++;
					int ecount=0;
					if(i+dir>=0 && i+dir<size)
						for(int k=-1;k<=1;k+=2)
							if(j+k>=0 && j+k<size)
								if(board[i+dir][j+k]!=color && board[i+dir][j+k]!=' ')
									ecount++;
					if(ecount && !count)
						count=-10000;
//					int enemyCount=0;
/*					for(int ii=i+dir;ii>=0 && ii<size;ii+=dir)
						for(int jj=j-1;jj<=j+1;++jj)
							if(jj>=0 && jj<size && board[ii][jj]!=color && board[ii][jj]!=' ')
								enemyCount++;*/
					r+=1+attackCoef*(1+count*defenceCoef)*abs(ourLine-i)//+100/(0.0001+enemyCount)
						+(size-abs(ourLine-i))*100*(backFlag[i][j] && enemyFlag[i][j]);
				}
		return r*generalCoef;
	}

	int maxDistance(int color,int line) const
	{
		int r=0x3fffffff;
		for(int i=0;i<size;++i)
			for(int j=0;j<size;++j)
				if(board[i][j]==color)
					r=min(r,abs(i-line));
		return r;
	}
};

Board board;
char ourColor='B';

struct Table
{
	char color;
	int q[size][size];

	void calculate(const Board& board)
	{
		for(int i=0;i<size;++i)
			fill(q[i],q[i]+size,0);
		for(int i=0;i<size;++i)
			for(int j=0;j<size;++j)
				if(board[i][j]==color)
					if(color=='W')
					{
						for(int ii=i;ii<size;++ii)
							for(int jj=0;jj<size;++jj)
								if(ii-i>=abs(jj-j))
									q[ii][jj]++;
					}
					else
					{
						for(int ii=i;ii>=0;--ii)
							for(int jj=0;jj<size;++jj)
								if(i-ii>=abs(jj-j))
									q[ii][jj]++;
					}
	}

	void print()
	{
		for(int i=size-1;i>=0;--i)
		{
			for(int j=0;j<size;++j)
				printf("%d ",q[i][j]);
			printf("\n");
		}
		printf("\n");
	}
};
Table wt,bt;
Table *ourT,*enemyT;

int howGood(const Table& our, const Table& enemy)
{
	int r=0;
	for(int i=0;i<size;++i)
		for(int j=0;j<size;++j)
//			r-=sign(our.q[i][j]-enemy.q[i][j])*sqr(our.q[i][j]-enemy.q[i][j]);
			r+=sign(our.q[i][j]-enemy.q[i][j]);
	return r;
}

void printMove(int si,int sj,int ei,int ej)
{
	char buf[10];
	buf[0]='a'+sj;
	buf[1]='1'+si;
	buf[2]='a'+ej;
	buf[3]='1'+ei;
	buf[4]=0;
	cout<<buf<<endl;
}

void ourMove()
{
	enemyT->calculate(board);
	int maxI=-1,maxJ=-1,maxK=-1;
	double maxGood=-1e30;
	int ourDir=ourColor=='W' ? 1 : -1;
	int ourLine=ourColor=='W' ? 0 : 7;
	int enemyLine=ourColor=='W' ? 7 : 0;
	for(int i=0;i<size;++i)
		for(int j=0;j<size;++j)
			if(board[i][j]==ourColor && i+ourDir<size && i+ourDir>=0)
				for(int k=-1;k<=1;++k)
					if(j+k>=0 && j+k<size && board.canMove(i,j,ourDir,k,ourColor))
					{
						int ei=i+ourDir;
						int ej=j+k;
						double good=0;
						if(board[ei][ej]!=' ')
							good+=10000000;
						if(ei==enemyLine)
							good=1e30;
						
						Board b=board;
						b.makeMove(i,j,ei,ej);
						good+=b.defence(ourColor,ourDir,ourLine);
						good+=ej*30;

						if(good>maxGood)
						{
							maxGood=good;
							maxI=i;
							maxJ=j;
							maxK=k;
						}
					}

	printMove(maxI,maxJ,maxI+ourDir,maxJ+maxK);
	board.makeMove(maxI,maxJ,maxI+ourDir,maxJ+maxK);
	ourT->calculate(board);
}

void enemyMove(const char* buf)
{
	int sj=buf[0]-'a';
	int si=buf[1]-'1';
	int ej=buf[2]-'a';
	int ei=buf[3]-'1';
	board.makeMove(si,sj,ei,ej);
}

void initialize()
{
	static bool first=true;
	if(first)
	{
		first=false;
		wt.color='W';
		bt.color='B';
		ourT=&wt;
		enemyT=&bt;
		if(ourColor=='B')
			swap(ourT,enemyT);
	}
}

int main()
{
	for(int i=0;i<size;++i)
		fill(board[i],board[i]+size,' ');
	for(int i=0;i<size;++i)
	{
		board[0][i]=board[1][i]='W';
		board[size-1][i]=board[size-2][i]='B';
	}

	static char buf[1000];
	for(;;)
	{
		gets(buf);
		if(strcmp(buf,"Name")==0)
			cout<<"SUrSU Thinker"<<endl;
		else if(strcmp(buf,"Quit")==0)
			return 0;
		else if(strcmp(buf,"Start")==0)
		{
			ourColor='W';
			initialize();
			ourMove();
		}
		else
		{
			initialize();
			enemyMove(buf);
			ourMove();
		}
	}
	return 0;
}
