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

public class feb20 {

	// *** ++
	// +=-==+ +++=-
	// +-:---==+ *+=----=
	// +-:------==+ ++=------==
	// =-----------=++=========================
	// +--:::::---:-----============-=======+++====
	// +---:..:----::-===============-======+++++++++
	// =---:...---:-===================---===++++++++++
	// +----:...:-=======================--==+++++++++++
	// +-:------====================++===---==++++===+++++
	// +=-----======================+++++==---==+==-::=++**+
	// +=-----================---=======++=========::.:-+*****
	// +==::-====================--: --:-====++=+===:..-=+*****
	// +=---=====================-... :=..:-=+++++++++===++*****
	// +=---=====+=++++++++++++++++=-:::::-====+++++++++++++*****+
	// +=======++++++++++++=+++++++============++++++=======+******
	// +=====+++++++++++++++++++++++++==++++==++++++=:... . .+****
	// ++====++++++++++++++++++++++++++++++++++++++++-. ..-+****
	// +======++++++++++++++++++++++++++++++++===+====:. ..:=++++
	// +===--=====+++++++++++++++++++++++++++=========-::....::-=++*
	// ====--==========+++++++==+++===++++===========--:::....:=++*
	// ====---===++++=====++++++==+++=======-::--===-:. ....:-+++
	// ==--=--====++++++++==+++++++++++======--::::...::::::-=+++
	// ===----===++++++++++++++++++++============--=-==----==+++
	// =--------====++++++++++++++++=====================+++++++
	// =---------=======++++++++====+++=================++++++++
	// -----------========+++++++++++++++=================+++++++
	// =----------==========++++++++++=====================++++++++
	// =====------==============+++++++===================+++==+++++
	// =======------==========================================++++++

	// created by : Nitesh Gupta

	public static void main(String[] args) throws Exception {

		// first();
		// sec();
		// third();
//			four();
		fif();
		// six();
	}

	private static void first() throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] scn = (br.readLine()).trim().split(" ");
		StringBuilder sb = new StringBuilder();

		int n = Integer.parseInt(scn[0]);

		int count = 0;
		for (int i = 0; i <= n + 1; i++) {
			count += 1;
			int j = i;
			sb.append(i + " " + j + " \n");
		}
		for (int i = 1; i <= n + 1; i++) {
			count += 1;
			int j = i - 1;
			sb.append(i + " " + j + " \n");
		}
		for (int j = 1; j <= n + 1; j++) {
			count += 1;
			int i = j - 1;
			sb.append(i + " " + j + " \n");
		}

		System.out.println(count);
		System.out.println(sb);
		return;
	}

	private static void sec() throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] scn = (br.readLine()).trim().split(" ");
		StringBuilder sb = new StringBuilder();
		int n = Integer.parseInt(scn[0]);
		long[] arr = new long[n];
		scn = (br.readLine()).trim().split(" ");
		HashMap<Long, Integer> map = new HashMap<>();
		for (int i = 0; i < n; i++) {
			arr[i] = Long.parseLong(scn[i]);
			map.put(arr[i], map.getOrDefault(arr[i], 0) + 1);
		}

		TreeSet<Long> present = new TreeSet<>();
		TreeSet<Long> set = new TreeSet<>();

		long start = 0;
		boolean can = true;
		long[] ans = new long[n];
		for (int i = 0; i < n; i++) {
			while (map.containsKey(start) && map.get(start) > 0) {
				present.add(start);
				start += 1;
			}

			if (start != arr[i]) {
				if (!set.isEmpty()) {
					ans[i] = set.pollFirst();
				} else {
					ans[i] = start;
					start += 1;
				}
			}
			int f = map.remove(arr[i]);
			if (f > 1) {
				map.put(arr[i], f - 1);
			} else {
				if (present.contains(arr[i])) {
					present.remove(arr[i]);
					set.add(arr[i]);
				}

			}
		}
		TreeSet<Long> chck = new TreeSet<>();
		for (long i = 0; i <= n; i++) {
			chck.add(i);
		}
		can = true;
		for (int i = 0; i < n; i++) {
			chck.remove(ans[i]);
			if (chck.first() == arr[i]) {

			} else {
				can = false;
				break;
			}
		}
		if (!can) {
			sb.append("-1");
		} else {
			for (long ele : ans) {
				sb.append(ele + " ");
			}
		}

		System.out.println(sb);
		return;
	}

	private static void third() throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] scn = (br.readLine()).trim().split(" ");
		int t = Integer.parseInt(scn[0]);
		StringBuilder sb = new StringBuilder();

		while (t-- > 0) {
			scn = (br.readLine()).trim().split(" ");
			int n = Integer.parseInt(scn[0]);
			int x = Integer.parseInt(scn[1]);
			long[] arr = new long[n];
			scn = (br.readLine()).trim().split(" ");
			long sum = 0;
			int f = n, s = -1;
			boolean all = true;
			for (int i = 0; i < n; i++) {
				arr[i] = Long.parseLong(scn[i]);
				arr[i] %= x;
				sum += arr[i];
				sum %= x;
				if (arr[i] != 0) {
					f = Math.min(f, i);
					s = Math.max(s, i);
					all = false;
				}
			}

			int max = -1;
			if (sum != 0) {
				max = n;
			} else {
				if (all) {
					max = -1;
				} else {
					max = n - Math.min(f + 1, n - s);
				}
			}

			sb.append(max);
			sb.append("\n");
		}
		System.out.println(sb);
		return;
	}

	private static void four() throws Exception {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] scn = (br.readLine()).trim().split(" ");
		int t = Integer.parseInt(scn[0]);
		StringBuilder sb = new StringBuilder();

		while (t-- > 0) {
			scn = (br.readLine()).trim().split(" ");
			int n = Integer.parseInt(scn[0]);
			long[] arr = new long[n];
			scn = (br.readLine()).trim().split(" ");
			for (int i = 0; i < n; i++) {
				arr[i] = Long.parseLong(scn[i]);
			}
			int[] peak = new int[n];
			peak[0] = 1;
			peak[n - 1] = 1;
			int count = 2;
			for (int i = 1; i < n - 1; i++) {
				if (arr[i] < arr[i + 1] && arr[i] < arr[i - 1]) {
					peak[i] = 1;
					count += 1;
				}
				if (arr[i] > arr[i + 1] && arr[i] > arr[i - 1]) {
					peak[i] = 1;
					count += 1;
				}

			}
			sb.append(count + "\n");
			for (int i = 0; i < n; i++) {
				if (peak[i] == 1) {
					sb.append(arr[i] + " ");
				}
			}

			sb.append("\n");
		}
		System.out.println(sb);
		return;
	}

	private static void fif() throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] scn = (br.readLine()).trim().split(" ");
		int t = Integer.parseInt(scn[0]);
		StringBuilder sb = new StringBuilder();

		while (t-- > 0) {
			scn = (br.readLine()).trim().split(" ");
			int n = Integer.parseInt(scn[0]);
			int m = Integer.parseInt(scn[1]);
			char[][] arr = new char[n][m];
			int good = 0, bad = 0;
			for (int i = 0; i < n; i++) {
				String str = (br.readLine());
				for (int j = 0; j < m; j++) {
					arr[i][j] = str.charAt(j);
					if (arr[i][j] == 'G')
						good += 1;
					if (arr[i][j] == 'B')
						bad += 1;
				}
			}
			boolean can = true;
			if (bad == 0 || good == 0) {
				sb.append("YES");
			} else {
				ArrayList<Integer> list = new ArrayList<>();
				int[] row = { -1, 0, 0, 1 };
				int[] col = { 0, -1, 1, 0 };
				for (int i = 0; i < n; i++) {
					for (int j = 0; j < m; j++) {
						if (arr[i][j] == 'B') {
							for (int k = 0; k < 4; k++) {
								int nx = i + row[k];
								int ny = j + col[k];
								if (nx < 0 || ny < 0 || nx > n - 1 || ny > m - 1 || arr[nx][ny] == '#'||arr[nx][ny]=='B')
									continue;
								if(arr[nx][ny] == 'G') {
									can = false;
									break;
								}
								arr[nx][ny] = '#';
							}
						}
						if(!can)break;
						if (arr[i][j] == 'G') {
							list.add(i);
							list.add(j);
						}

					}
					if(!can)break;
				}
//				print(arr);
				if (arr[n - 1][m - 1] != '.') {
					can = false;
				} else {
					for (int i = 0; i < list.size(); i += 2) {
						if (!bfs(arr, list.get(i).intValue(), list.get(i + 1).intValue(), n, m)) {
							can = false;
							break;
						}
					}
					
				}

				if (can) {
					sb.append("YES");

				} else {
					sb.append("NO");
				}
			}

			sb.append("\n");
		}
		System.out.println(sb);
		return;
	}

	private static boolean bfs(char[][] arr, int x, int y, int n, int m) {
		// TODO Auto-generated method stub
		LinkedList<pair> q = new LinkedList<>();
		q.addLast(new pair(x, y));
		boolean[][] vis = new boolean[n][m];
		int[] row = { -1, 0, 0, 1 };
		int[] col = { 0, -1, 1, 0 };
		while (!q.isEmpty()) {
			pair rp = q.removeFirst();
			if (vis[rp.x][rp.y])
				continue;
			if (rp.x == n - 1 && rp.y == m - 1)
				return true;
			vis[rp.x][rp.y] = true;
			for (int k = 0; k < 4; k++) {
				int nx = rp.x + row[k];
				int ny = rp.y + col[k];
				if (nx < 0 || ny < 0 || nx > n - 1 || ny > m - 1 || arr[nx][ny] == '#')
					continue;
				q.addLast(new pair(nx, ny));
			}
		}
		return false;

	}

	static class pair {
		int x, y;

		pair(int a, int b) {
			x = a;
			y = b;

		}
	}

	private static void six() throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] scn = (br.readLine()).trim().split(" ");
		int t = Integer.parseInt(scn[0]);
		StringBuilder sb = new StringBuilder();

		while (t-- > 0) {
			scn = (br.readLine()).trim().split(" ");
			int n = Integer.parseInt(scn[0]);
			long[] arr = new long[n];
			scn = (br.readLine()).trim().split(" ");
			for (int i = 0; i < n; i++) {
				arr[i] = Long.parseLong(scn[i]);
			}

			sb.append("\n");
		}
		System.out.println(sb);
		return;
	}

	public static void sort(long[] arr) {
		int n = arr.length;
		for (int i = 0; i < n; i++) {
			int idx = (int) Math.random() * n;
			long temp = arr[i];
			arr[i] = arr[idx];
			arr[idx] = temp;
		}
		Arrays.sort(arr);
	}

	public static void print(char[][] dp) {
		for (char[] a : dp) {
			for (char ele : a) {
				System.out.print(ele + " ");
			}
			System.out.println();
		}
	}

}
