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

public class aaaaaaaaaaaaaaaa {
	boolean[][] visited;
	int bmoves;
	public void run() throws Exception {
		FastReader file = new FastReader();
		int times = file.nextInt();
		for (int asdf = 0; asdf < times; asdf++) {
			int r = file.nextInt(), c = file.nextInt();
			char[][] mat = new char[r][c];
			for (int i = 0; i < r; i++) {
				mat[i] = file.next().toCharArray();
			}
			int gcnt = 0;
			//surround all Bs
			for (int i = 0; i < r; i++) {
				for (int j = 0; j < c; j++) {
					if (mat[i][j] == 'B') {
						if (i + 1 < r &&mat[i+1][j] == '.') mat[i+1][j] = '#';
						if (i - 1 >= 0 && mat[i-1][j] == '.') mat[i-1][j] = '#';
						if (j + 1 < c && mat[i][j+1] == '.') mat[i][j+1] = '#';
						if (j - 1 >= 0 && mat[i][j-1] == '.') mat[i][j-1] = '#';
					}
					else if (mat[i][j] == 'G') gcnt++;
				}
			}
			//check for each G to see if it works
			boolean works = true;
			if (gcnt == 0) works = true;
			else if(mat[r-1][c-1] == '#' || mat[r-1][c-1] == 'B') works = false;
			else {
				for (int i = 0; i < r; i++) {
					for (int j = 0; j < c; j++) {
						if (mat[i][j] == 'G') {
							visited = new boolean[r][c];
							bmoves = Integer.MAX_VALUE;
							Queue<Integer> q = new LinkedList<Integer>();	//e
							q.add(i); q.add(j); q.add(0); 		//e
							while(!q.isEmpty())								//e
							{
								int ro=q.poll();		//f
								int co=q.poll();		//f
								//System.out.println(ro + " "+ co);
								int steps=q.poll();	//f
								if(ro>=0 && ro<mat.length && co>=0 && co<mat[ro].length && !visited[ro][co] && mat[ro][co] != '#')	//g
								{
									if(ro == mat.length - 1 && co == mat[ro].length - 1)	//h
									{					//h
										bmoves=steps;	//h
										break;			//h
									}
									visited[ro][co] = true;//h
									q.add(ro+1); q.add(co); q.add(steps+1);	//j
									q.add(ro-1); q.add(co); q.add(steps+1);	//j	
									q.add(ro); q.add(co+1); q.add(steps+1);	//j
									q.add(ro); q.add(co-1); q.add(steps+1);	//j
								}
								
							}
							if (bmoves == Integer.MAX_VALUE) {
								works = false;
								break;
							}
						}
					}
					if (!works) break;
				}
			}
			System.out.println(works ? "Yes" :"No");
		}
	}

	public static void main(String[] args) throws Exception {
		new aaaaaaaaaaaaaaaa().run();
	}

	static class FastReader {
		BufferedReader br;
		StringTokenizer st;

		public FastReader() {
			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());
		}

		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
}
