import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.HashMap;

public class Div2_648 {

	static class Reader {

		final private int BUFFER_SIZE = 1 << 12;
		boolean consume = false;
		private byte[] buffer;
		private int bufferPointer, bytesRead;
		private boolean reachedEnd = false;

		public Reader() {
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = 0;
			bytesRead = 0;
		}

		public boolean hasNext() {
			return !reachedEnd;
		}

		private void fillBuffer() throws IOException {
			bytesRead = System.in.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1) {
				buffer[0] = -1;
				reachedEnd = true;
			}
		}

		private void consumeSpaces() throws IOException {
			while (read() <= ' ' && reachedEnd == false)
				;
			bufferPointer--;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead) {
				fillBuffer();
			}
			return buffer[bufferPointer++];
		}

		public String next() throws IOException {
			StringBuilder sb = new StringBuilder();
			consumeSpaces();
			byte c = read();
			do {
				sb.append((char) c);
			} while ((c = read()) > ' ');
			if (consume) {
				consumeSpaces();
			}
			;
			if (sb.length() == 0) {
				return null;
			}
			return sb.toString();
		}

		public String nextLine() throws IOException {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String str = br.readLine();
			return str;
		}

		public int nextInt() throws IOException {
			consumeSpaces();
			int ret = 0;
			byte c = read();
			boolean neg = (c == '-');
			if (neg) {
				c = read();
			}
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (consume) {
				consumeSpaces();
			}
			if (neg) {
				return -ret;
			}
			return ret;
		}

		public long nextLong() throws IOException {
			consumeSpaces();
			long ret = 0;
			byte c = read();
			boolean neg = (c == '-');
			if (neg) {
				c = read();
			}
			do {
				ret = ret * 10L + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (consume) {
				consumeSpaces();
			}
			if (neg) {
				return -ret;
			}
			return ret;
		}

		public double nextDouble() throws IOException {
			consumeSpaces();
			double ret = 0;
			double div = 1;
			byte c = read();
			boolean neg = (c == '-');
			if (neg) {
				c = read();
			}
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}
			if (consume) {
				consumeSpaces();
			}
			if (neg) {
				return -ret;
			}
			return ret;
		}

		public int[] nextIntArray(int n) throws IOException {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = nextInt();
			}
			return a;
		}

		public int[][] nextIntMatrix(int n, int m) throws IOException {
			int[][] grid = new int[n][m];
			for (int i = 0; i < n; i++) {
				grid[i] = nextIntArray(m);
			}
			return grid;
		}

		public char[][] nextCharacterMatrix(int n) throws IOException {
			char[][] a = new char[n][];
			for (int i = 0; i < n; i++) {
				a[i] = next().toCharArray();
			}
			return a;
		}

		public void close() throws IOException {
			if (System.in == null) {
				return;
			} else {
				System.in.close();
			}
		}
	}

	static Reader r = new Reader();
	static PrintWriter out = new PrintWriter(System.out);

	private static void solve1() throws IOException {

		int t = r.nextInt();
		StringBuilder res = new StringBuilder();

		while (t-- > 0) {

			int n = r.nextInt();
			int m = r.nextInt();

			int arr[][] = r.nextIntMatrix(n, m);

			boolean row[] = new boolean[n];
			boolean col[] = new boolean[m];

			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					if (arr[i][j] == 1) {
						row[i] = true;
						col[j] = true;
					}
				}
			}

			int chance = 0;

			while (true) {
				boolean flag = false;
				for (int i = 0; i < n; i++) {
					for (int j = 0; j < m; j++) {
						if (arr[i][j] == 0) {
							if (!row[i] && !col[j]) {
								arr[i][j] = 1;
								row[i] = true;
								col[j] = true;
								flag = true;
								if (chance == 0) {
									chance = 1;
								} else {
									chance = 0;
								}
							}
						}
					}
				}
				if (!flag) {
					if (chance == 1)
						res.append("Ashish");
					else
						res.append("Vivek");
					break;
				}
			}
			res.append("\n");

		}

		out.print(res);
		out.close();
	}

	private static boolean isSorted(int arr[]) {
		for (int i = 1; i < arr.length; i++) {
			if (arr[i] < arr[i - 1]) {
				return false;
			}
		}
		return true;
	}

	private static void solve2() throws IOException {

		int t = r.nextInt();
		StringBuilder res = new StringBuilder();

		while (t-- > 0) {

			int n = r.nextInt();

			int a[] = r.nextIntArray(n);
			int b[] = r.nextIntArray(n);

			boolean flag = isSorted(a);

			if (!flag) {
				int zero = 0, one = 0;
				for (int i = 0; i < n; i++) {
					if (b[i] == 0) {
						zero++;
					} else {
						one++;
					}
				}
				if (zero != n && one != n) {
					flag = true;
				}
			}

			res.append(flag ? "Yes" : "No").append("\n");

		}

		out.print(res);
		out.close();

	}

	private static void solve3() throws IOException {

		int n = r.nextInt();

		int arr[] = r.nextIntArray(n);

		HashMap<Integer, Integer> pos = new HashMap<Integer, Integer>();
		for (int i = 1; i <= n; i++) {
			pos.put(r.nextInt(), i);
		}

		int freq[] = new int[(int) 2e5 + 5];
		for (int i = 0; i < n; i++) {
			i++;
			if (i < pos.get(arr[i - 1])) {
				freq[pos.get(arr[i - 1]) - i]++;
			} else if (i == pos.get(arr[i - 1])) {
				freq[0]++;
				freq[n]++;
			} else {
				freq[pos.get(arr[i - 1]) + n - i]++;
			}
			i--;
		}

		int max = Integer.MIN_VALUE;
		for (int i = 0; i < freq.length; i++) {
			if (freq[i] > max) {
				max = freq[i];
			}
		}

		out.print(max);
		out.close();

	}

	static class Pair {
		int fi, se;

		public Pair(int a, int b) {
			fi = a;
			se = b;
		}
	}

	static boolean visited[][], blocked[][];
	static char maze[][];

	private static void DFS(int row, int col) {
		if (blocked[row][col] || visited[row][col] || row < 0 || col < 0 || row >= maze.length
				|| col >= maze[0].length) {
			return;
		}
		visited[row][col] = true;
		if (row - 1 >= 0) {
			DFS(row - 1, col);
		}
		if (row + 1 < maze.length) {
			DFS(row + 1, col);
		}
		if (col - 1 >= 0) {
			DFS(row, col - 1);
		}
		if (col + 1 < maze[0].length) {
			DFS(row, col + 1);
		}
	}

	private static void solve4() throws IOException {

		int t = r.nextInt();
		StringBuilder res = new StringBuilder();

		while (t-- > 0) {

			int n = r.nextInt();
			int m = r.nextInt();

			visited = new boolean[n][m];
			blocked = new boolean[n][m];
			maze = new char[n][m];

			for (int i = 0; i < n; i++) {
				maze[i] = r.next().toCharArray();
			}

			boolean flag = true;

			for (int i = 0; i < n; i++) {
				for (int j = 0; j < m; j++) {
					if (maze[i][j] == 'B') {
						if ((j + 1 < m && maze[i][j + 1] == 'G') || (j - 1 >= 0 && maze[i][j - 1] == 'G')
								|| (i + 1 < n && maze[i + 1][j] == 'G') || (i - 1 >= 0 && maze[i - 1][j] == 'G')) {
							flag = false;
							break;
						}
						blocked[i][j] = true;
						if (i - 1 >= 0) {
							blocked[i - 1][j] = true;
						}
						if (i + 1 < n) {
							blocked[i + 1][j] = true;
						}
						if (j - 1 >= 0) {
							blocked[i][j - 1] = true;
						}
						if (j + 1 < m) {
							blocked[i][j + 1] = true;
						}
					}
				}
			}

			if (flag) {
				DFS(n - 1, m - 1);
				for (int i = 0; i < n; i++) {
					for (int j = 0; j < m; j++) {
						if (maze[i][j] == 'G' && !visited[i][j]) {
							flag = false;
							break;
						}
					}
				}
			}

			res.append(flag ? "YES" : "NO").append("\n");

		}

		out.print(res);
		out.close();

	}

	private static void solve5() throws IOException {

		int t = r.nextInt();
		StringBuilder res = new StringBuilder();

		while (t-- > 0) {

			int n = r.nextInt();

			res.append(false).append("\n");
		}

		out.print(res);
		out.close();
	}

	private static void solve6() throws IOException {

		int t = r.nextInt();
		StringBuilder res = new StringBuilder();

		while (t-- > 0) {

			int n = r.nextInt();

			res.append(false).append("\n");
		}

		out.print(res);
		out.close();
	}

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

//		solve1();

//		solve2();

//		solve3();

		solve4();

		// solve5();

		// solve6();

	}

}