import java.util.*;
public class smaze {
	
	public static char[][] grid;
	public static boolean[][] vis;
	public static boolean res;
	public static int n, m;
	
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int tc = in.nextInt();
		for (int t = 1; t <= tc; t++) {
			n = in.nextInt();
			m = in.nextInt();
			grid = new char[n][m];
			for (int i = 0; i < n; i++) {
				String res = in.next();
				for (int j = 0; j < m; j++) {
					grid[i][j] = res.charAt(j);
				}
			}
			res = true;
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					if (grid[i][j] == 'B') {
						if (i-1 >= 0 && grid[i-1][j] == 'G') res = false;
						if (i+1 < n && grid[i+1][j] == 'G') res = false;
						if (j-1 >= 0 && grid[i][j-1] == 'G') res = false;
						if (j+1 < m && grid[i][j+1] == 'G') res = false;
						
						if (i-1 >= 0 && grid[i-1][j] == '.') grid[i-1][j] = '#';
						if (i+1 < n && grid[i+1][j] == '.') grid[i+1][j] = '#';
						if (j-1 >= 0 && grid[i][j-1] == '.') grid[i][j-1] = '#';
						if (j+1 < m && grid[i][j+1] == '.') grid[i][j+1] = '#';
					}
				}
			}
			
			vis = new boolean[n][m];
			if (grid[n-1][m-1] != '#')
				dfs(n-1, m-1);
			
			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					if (grid[i][j] == 'G') res = false;
				}
			}
			System.out.println(res ? "YES" : "NO");
		}
		
		
	}
	
	public static void dfs(int i, int j) {
		if (vis[i][j] == true) return;
		vis[i][j] = true;
		grid[i][j] = 'W';
		if (i-1 >= 0 && (grid[i-1][j] == '.' || grid[i-1][j] == 'G')) dfs(i-1, j);
		if (i+1 < n && (grid[i+1][j] == '.' || grid[i+1][j] == 'G')) dfs(i+1, j);
		if (j-1 >= 0 && (grid[i][j-1] == '.' || grid[i][j-1] == 'G')) dfs(i, j-1);
		if (j+1 < m && (grid[i][j+1] == '.' || grid[i][j+1] == 'G')) dfs(i, j+1);
	}
}
