// Random bot for "Breakthrough" game
// Ural Championship 2010 Game Tour
// Author: Vladimir Yakovlev

using System;
using System.Collections.Generic;

public class RandomBot
{
	public RandomBot()
	{
		board = new Cell[BOARD_SIZE,BOARD_SIZE];
		for(int x = 0; x < BOARD_SIZE; x++)
		{
			Cell cell = (x <= 1 ? Cell.WHITE : (x >= BOARD_SIZE - 2 ? Cell.BLACK : Cell.EMPTY));
			for(int y = 0; y < BOARD_SIZE; y++)
				board[x, y] = cell;
		}
		currentColor = Cell.WHITE;
		random = new Random(314159265);
	}

	private static void Main()
	{
		new RandomBot().Run();
	}

	private void Run()
	{
		while(true)
		{
			string command = Console.ReadLine();
			if(command == "Quit")
				break;
			if(command == "Name")
			{
				Console.WriteLine("C# Random Bot");
				Console.Out.Flush();
				continue;
			}
			if(command != "Start")
				MakeMove(GameMove.Parse(command));
			GameMove move = GetRandomMove();
			MakeMove(move);
			Console.WriteLine(move.ToString());
			Console.Out.Flush();
		}
	}

	private void MakeMove(GameMove move)
	{
		board[move.ex, move.ey] = board[move.sx, move.sy];
		board[move.sx, move.sy] = Cell.EMPTY;
		currentColor = (currentColor == Cell.WHITE ? Cell.BLACK : Cell.WHITE);
	}

	private GameMove GetRandomMove()
	{
		List<GameMove> moves = new List<GameMove>();
		for(int sx = 0; sx < BOARD_SIZE; sx++)
		{
			for(int sy = 0; sy < BOARD_SIZE; sy++)
			{
				if(board[sx, sy] == currentColor)
				{
					for(int dy = -1; dy <= 1; dy++)
					{
						int ex = sx + (currentColor == Cell.WHITE ? 1 : -1);
						int ey = sy + dy;
						if((ex >= 0 && ex < BOARD_SIZE && ey >= 0 && ey < BOARD_SIZE) &&
						   (dy != 0 && board[ex, ey] != currentColor || board[ex, ey] == Cell.EMPTY))
							moves.Add(new GameMove(sx, sy, ex, ey));
					}
				}
			}
		}
		return moves[random.Next(moves.Count)];
	}

	private readonly Random random;
	private readonly Cell[,] board;
	private Cell currentColor;
	private const int BOARD_SIZE = 8;

	private enum Cell
	{
		EMPTY,
		WHITE,
		BLACK
	}

	private class GameMove
	{
		public GameMove(int sx, int sy, int ex, int ey)
		{
			this.sx = sx;
			this.sy = sy;
			this.ex = ex;
			this.ey = ey;
		}

		public static GameMove Parse(string move)
		{
			return new GameMove(move[1] - '1', move[0] - 'a', move[3] - '1', move[2] - 'a');
		}

		public override string ToString()
		{
			return string.Format("{0}{1}{2}{3}", (char)(sy + 'a'), sx + 1, (char)(ey + 'a'), ex + 1);
		}

		public readonly int sx;
		public readonly int sy;
		public readonly int ex;
		public readonly int ey;
	}
}