// Arup Guha
// 8/2/2026
// Solution to 1989 UCF HS Programming Contest Problem: Reversi

import java.util.*;

public class reversi {

	// Directions words could be.
	final public static int[] DR = {-1,-1,-1,0,0,1,1,1};
	final public static int[] DC = {-1,0,1,-1,1,-1,0,1};
	final public static int N = 8;
	
	public static char[][] g;
	
	public static void main(String[] args) {
	
		// Get size.
		Scanner stdin = new Scanner(System.in);
		
		while (stdin.hasNext()) {
		
			// Read grid.
			g = new char[N][];
			for (int i=0; i<N; i++)
				g[i] = stdin.next().toCharArray();
				
			// Get the piece for which we evaluate this.
			String piece = stdin.next();
			char whoseMove = (piece.equals("Black")) ? 'X' : 'O';
			
			// Store valid moves here.
			ArrayList<String> moves = new ArrayList<String>();
			
			// This is the order they use in the sample for printing.
			for (int i=N-1; i>=0; i--) 
				for (int j=0; j<N; j++) 
					if (isValid(i, j, whoseMove))
						moves.add(""+(char)('A'+j)+(N-i));
						
			// Get this out of the way.
			if (moves.size() == 0)
				System.out.println(piece+" has no legal moves");
			
			// Regular case.
			else {
				System.out.print(piece+" has legal moves at");
				for (int i=0; i<moves.size()-1; i++)
					System.out.print(" "+moves.get(i)+",");
				System.out.println(" "+moves.get(moves.size()-1));
			}
		}
	}
	
	
	
	// Returns true iff w is in the grid starting at row sR, ending at column sC in
	// direction d.
	public static boolean isValid(int r, int c, char piece) {
		
		// Can't move somewhere that already has a piece.
		if (g[r][c] != '.') return false;
		
		// Just to make easier to read.
		char oppPiece = piece == 'X' ? 'O' : 'X';
		
		// Try each direction.
		for (int i=0; i<DR.length; i++) {
		
			int j;
			
			// Looking for opposite piece.
			int curState = 0;
			
			// j is how many spots away. Will stop when we get to a space or our color.
			for (j=1;;j++) {
				
				// Where I am now.
				int curR = r + j*DR[i];
				int curC = c + j*DC[i];
				
				// Can't go off the board.
				if (!inbounds(curR, curC)) break;
				
				// Get the piece.
				char curP = g[curR][curC];
					
				// I didn't capture anything.
				if (curState == 0 && curP != oppPiece) break;
				
				// Can't do it.
				if (curState == 1 && curP == '.') break;
				
				// We completed a run of theirs and now it's mine again, so we did it!
				if (curState == 1 && curP == piece) return true;
				
				// state = 1 means that I can have more of their piece or end on mine.
				if (curState == 0) curState = 1;
			}
		}
		
		// If we get here nothing worked.
		return false;
	}
	
	// Returns true iff row x, column y is inbounds.
	public static boolean inbounds(int x, int y) {
		return x >= 0 && x < N && y >= 0 && y < N;
	}
}
		