// Arup Guha
// 7/18/2016
// Originally written for SI@UCF Competition Camp

import java.util.*;

public class bunnies_arup {
	
	public static char[][] grid;
	public static int r;
	public static int c;
	
	// Valid ways to move from a square.
	final public static int[] DX = {-1,0,0,1};
	final public static int[] DY = {0,-1,1,0};
	
	public static void main(String[] args) {
		
		Scanner stdin = new Scanner(System.in);
		int numCases = stdin.nextInt();
		
		// Process each case.
		for (int loop=0; loop<numCases; loop++) {
			
			r = stdin.nextInt();
			c = stdin.nextInt();
			grid = new char[r][];
			
			// Get grid.
			for (int i=0; i<r; i++) 
				grid[i] = stdin.next().toCharArray();
				
			// Find rabbits.
			int peter = find('P');
			int cottontail = find('C');
			
			// Keeps track of where we've been.
			boolean[][] visited = new boolean[r][c];
			
			// Fill every location reachable from peter in the grid.
			fill(peter/c, peter%c, visited);
			
			// Output appropriate result.
			if (visited[cottontail/c][cottontail%c])
				System.out.println("yes");
			else
				System.out.println("no");
			
		}	
	}
	
	public static void fill(int x, int y, boolean[][] visited) {
		
		visited[x][y] = true;
		
		// Go to all unvisited neighbors that are valid.
		for (int i=0; i<DX.length; i++) {
			
			int nextx = x + DX[i];
			int nexty = y + DY[i];
			
			// Skip if this is a bad or invalid square.
			if (!inbounds(nextx, nexty) || visited[nextx][nexty] || grid[nextx][nexty] == '#')
				continue;
				
			// Recursively search from this neighbor square.
			fill(nextx, nexty, visited);
			
		}
	}
	
	public static boolean inbounds(int x, int y) {
		return x >= 0 && x < r && y >= 0 && y < c;
	}
	
	
	// Returns the first location c occurs in grid. -1 if not found.
	public static int find(char ch) {
		
		for (int i=0; i<r; i++)
			for (int j=0; j<c; j++)
				if (grid[i][j] == ch)
					return i*c + j;
					
		return -1;
	}
}