Problem: Vivek has encountered a problem. He has a maze that can be represented as an n × m grid. Each of the grid cells may represent the following:

  * Empty — '.' 
  * Wall — '#' 
  * Good person — 'G' 
  * Bad person — 'B' 



The only escape from the maze is at cell (n, m).

A person can move to a cell only if it shares a side with their current cell and does not contain a wall. Vivek wants to block some of the empty cells by replacing them with walls in such a way, that all the good people are able to escape, while none of the bad people are able to. A cell that initially contains 'G' or 'B' cannot be blocked and can be travelled through.

Help him determine if there exists a way to replace some (zero or more) empty cells with walls to satisfy the above conditions.

It is guaranteed that the cell (n,m) is empty. Vivek can also block this cell.

Input

The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers n, m (1 ≤ n, m ≤ 50) — the number of rows and columns in the maze.

Each of the next n lines contain m characters. They describe the layout of the maze. If a character on a line equals '.', the corresponding cell is empty. If it equals '#', the cell has a wall. 'G' corresponds to a good person and 'B' corresponds to a bad person.

Output

For each test case, print "Yes" if there exists a way to replace some empty cells with walls to satisfy the given conditions. Otherwise print "No"

You may print every letter in any case (upper or lower).

Example

Input


6
1 1
.
1 2
G.
2 2
#B
G.
2 3
G.#
B#.
3 3
#B.
#..
GG.
2 2
#B
B.


Output


Yes
Yes
No
No
Yes
Yes

Note

For the first and second test cases, all conditions are already satisfied.

For the third test case, there is only one empty cell (2,2), and if it is replaced with a wall then the good person at (1,2) will not be able to escape.

For the fourth test case, the good person at (1,1) cannot escape.

For the fifth test case, Vivek can block the cells (2,3) and (2,2).

For the last test case, Vivek can block the destination cell (2, 2).

Solution (in JAVA):

Solution:
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 (maze[i][j] == 'B' || maze[i][j] == '#') {
						blocked[i][j] = 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();

	}

}