"""
Example Python program for the CodeCup 2009 game Pillars.
This example illustrates how I/O works with the CodeCup system.
Feel free to modify or use this code.
"""

import sys, random

# List-of-lists storing a map of the board.
# board[x][y] == 0 if the tile at (x, y) is empty.
board = [ [ 0 for y in range(10) ] for x in range(10) ]

def readPillars():
    """Read the positions of the initial 10 pillars."""
    for i in range(10):
        s = sys.stdin.readline()
        y = ord(s[0]) - ord('A')
        x = ord(s[1]) - ord('a')
        board[x][y] = 1

def processOpponentsMove(s):
    """Update the board to account for the opponent's move."""
    y1 = ord(s[0]) - ord('A')
    x1 = ord(s[1]) - ord('a')
    y2 = ord(s[2]) - ord('A')
    x2 = ord(s[3]) - ord('a')
    for x in range(x1, x2 + 1):
        for y in range(y1, y2 + 1):
            board[x][y] = 1

def doOwnMove():
    """Select the best move for us, write it to the output, and update
    the board.  This example just selects a random tile.
    It is up to you to make this function as smart as possible."""
    x = random.randint(0, 9)
    y = random.randint(0, 9)
    while board[x][y] != 0:
        y += 1
        if y == 10:
            y = 0
            x += 1
            if x == 10:
                x = 0
    # Found an empty spot in position (x, y)
    board[x][y] = 1
    print chr(y + ord('A')) + chr(x + ord('a')) + chr(y + ord('A')) + chr(x + ord('a'))
    sys.stdout.flush()

def main():
    """Main program."""
    readPillars()
    s = sys.stdin.readline().strip()
    if s == 'Start':
        # We play with Red.
        doOwnMove() 
        s = sys.stdin.readline().strip()
    while s != 'Quit':
        processOpponentsMove(s)
        doOwnMove()
        s = sys.stdin.readline().strip()

if __name__ == '__main__':
    # Call main() when the program starts.
    main()

# end


syntax highlighted by Code2HTML, v. 0.9.1