import java.util.*;
import java.io.*;

public class File {
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e) {
                    e.printStackTrace();
                }
            }

            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }	
	
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		
		
		
		
		int T = sc.nextInt();
		
		for (int t = 1; t <= T; t++) {
			int m = sc.nextInt();
			int n = sc.nextInt();
			
			char[][] grid = new char[m][n];
			
			LinkedList<int[]> goods = new LinkedList();
			LinkedList<int[]> bads = new LinkedList();
			
			for (int r = 0; r < m; r++) {
				String row = sc.next();
				
				for (char c = 0; c < n; c++) {
					grid[r][c] = row.charAt(c);
					
					if (grid[r][c] == 'G') {
						goods.add(new int[] {r, c});
					}
					else if (grid[r][c] == 'B') {
						bads.add(new int[] {r, c});
					}
				}							
			}
			
			boolean isPossible = true;
			// If there are no goods, we just block off the exit.
			// Only care that goods can escape, after blocking bads.
			if (goods.size() > 0) {
				for (int[] pair : bads) {
					int r = pair[0];
					int c = pair[1];
					
					if (grid[r][c] == 'B') {
						if (!DFS(grid, r, c)) {
							isPossible = false;
						}
					}
				}
				
				if (isPossible) {
					// How many goods can we reach from the exit
					int count = BFS(grid, m-1, n-1);
						
					if (count != goods.size()) {
						isPossible = false;
					}
				}
			}
			
			if (isPossible) {
				out.println("Yes");
			}
			else {
				out.println("No");
			}
		}
		
		
		out.close();
	}
	
	public static int[][] dirs = new int[][] {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
	
	// Return true if no 'G' encountered.
	public static boolean DFS(char[][] grid, int r, int c) {
		if (r < 0 || r >= grid.length || c < 0 || c >= grid[0].length) {
			return true;
		}
		
		boolean noGoods = true;
		grid[r][c] = '#';
		
		for (int[] dir : dirs) {
			int nextR = r + dir[0];
			int nextC = c + dir[1];
				
			if (nextR >= 0 && nextR < grid.length && nextC >= 0 && nextC < grid[0].length) {
				if (grid[nextR][nextC] == 'B') {
					if (!DFS(grid, nextR, nextC)) {
						noGoods = false;
					}
				}
				else if (grid[nextR][nextC] == 'G') {
					noGoods = false;
					break;
				}
				else if (grid[nextR][nextC] == '.') {
					grid[nextR][nextC] = '#';
				}
			}
		}
		
		return noGoods;
	}
	
	// Return how many 'G' we can reach.
	public static int BFS(char[][] grid, int r, int c) {
	    if (grid[r][c] == '#') return -1;
	    
		LinkedList<int[]> queue = new LinkedList();
		queue.add(new int[] {r, c});
		grid[r][c] = '#';
		int count = 0;
		
		while (!queue.isEmpty()) {
			int[] curr = queue.removeFirst();
			
			for (int[] dir : dirs) {
				int nextR = curr[0] + dir[0];
				int nextC = curr[1] + dir[1];
				
				if (nextR >= 0 && nextR < grid.length && nextC >= 0 && nextC < grid[0].length) {
					if (grid[nextR][nextC] != '#') {
						if (grid[nextR][nextC] == 'G') {
							count++;
						}
						
						grid[nextR][nextC] = '#';
						queue.addLast(new int[] {nextR, nextC});
					}
				}
			}
		}
		
		return count;
	}
}












	