/*------------------------------------------------------------
TEAM38
A
227
Target: CS35; Platform: Win32; Comment: C Sharp (.Net 3.5)
------------------------------------------------------------*/
﻿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 = GameMove.currentcolor = Cell.BLACK;
        GameMove.board = board;
        random = new Random();
    }

    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("USPU1 \"Berserker\"");
                Console.Out.Flush();
                continue;
            }
            if (command != "Start")
            {
                currentColor = (currentColor == Cell.WHITE ? Cell.BLACK : Cell.WHITE);
                GameMove.currentcolor = currentColor;
                MakeMove(GameMove.Parse(command));
            }
            currentColor = (currentColor == Cell.WHITE ? Cell.BLACK : Cell.WHITE);
            GameMove.currentcolor = currentColor;
            GameMove move = GetMove();
            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;
        
        GameMove.currentcolor = currentColor;
    }

    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 GameMove GetMove()
    {
        int safecolumn = -1;
        int unsafecolumn = -1;

        for (int y = 0; y < BOARD_SIZE; y++)
        {
            bool issafe = true;
            bool isunsafe = true;
            for (int x = 0; x < BOARD_SIZE; x++)
            {
                if (board[x, y] != currentColor) issafe = false;
                if (board[x, y] == currentColor) isunsafe = false;
            }
            if (issafe) safecolumn = y;
            if (isunsafe) unsafecolumn = y;
        }

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

        Cell enemy = currentColor == Cell.WHITE ? Cell.BLACK : Cell.WHITE;
        int ourside = currentColor == Cell.WHITE ? 0 : BOARD_SIZE - 1;

        // если на краю
        List<GameMove> filtered = new List<GameMove>();
        foreach (GameMove gm in moves)
        {
            if (gm.ex != (currentColor == Cell.WHITE ? BOARD_SIZE - 1 : 0)) continue;
            filtered.Add(gm);
        }
        if (filtered.Count > 0) return filtered[random.Next(filtered.Count)];

        // приоритет опсных безопасных полос
        filtered = new List<GameMove>();
        if (unsafecolumn != -1 || safecolumn != -1)
        {
            int chosecolumn = unsafecolumn != -1 ? unsafecolumn : safecolumn;
            foreach (GameMove gm in moves)
            {
                if (gm.sy == chosecolumn) filtered.Add(gm);
            }
        }
        if (filtered.Count > 0) return filtered[random.Next(filtered.Count)];

        // сначала валим ближнего кого можно безопасно
        filtered = new List<GameMove>();
        foreach (GameMove gm in moves)
        {
            if (!gm.IsKill) continue;
            //if (gm.IsUnSafe) continue;
            filtered.Add(gm);
        }
        //if (filtered.Count > 0) return filtered[random.Next(filtered.Count)];
        if (filtered.Count > 0)
        {
            int mind = BOARD_SIZE;
            GameMove closest = filtered[0];
            foreach (GameMove gm in filtered)
            {
                int dist = Math.Abs(gm.ex - ourside);
                if (dist < mind)
                {
                    mind = dist;
                    closest = gm;
                }
            }
            return closest;
        }

        // ходим куда безопасно
        filtered = new List<GameMove>();
        foreach (GameMove gm in moves)
        {
            if (gm.IsUnSafe) continue;
            filtered.Add(gm);
        }
        if (filtered.Count > 0) return filtered[random.Next(filtered.Count)];
        /*if (filtered.Count > 0)
        {
            int maxd = 0;
            GameMove farest = filtered[0];
            foreach (GameMove gm in filtered)
            {
                int dist = Math.Abs(gm.ex - ourside);
                if (dist > maxd)
                {
                    maxd = dist;
                    farest = gm;
                }
            }
            return farest;
        }*/

        // да хоть куданить...
        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;

            Cell enemy = currentcolor == Cell.WHITE ? Cell.BLACK : Cell.WHITE;
            int ourdest = currentcolor == Cell.WHITE ? BOARD_SIZE - 2 : 1;
            int dest = currentcolor == Cell.WHITE ? 1 : -1;
     
            IsSafe = true;
            if (ex + dest < BOARD_SIZE-1 && ex+dest > 0)
            {
                if (this.ey + 1 < BOARD_SIZE - 1 && board[ex + dest, this.ey + 1] == enemy) IsSafe = false;
                if (this.ey - 1 > 0 && board[ex + dest, this.ey - 1] == enemy) IsSafe = false;
            }
            IsUnSafe = !IsSafe;

            IsKill = board[ex, ey] == enemy;
        }

        public static GameMove Parse(string move)
        {
            currentcolor = currentcolor == Cell.WHITE ? Cell.BLACK : Cell.WHITE;
            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;

        public bool IsSafe;
        public bool IsKill;
        public bool IsUnSafe;

        public static Cell[,] board;
        public static Cell currentcolor;
    }
}
