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.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 (good == 0) {
				sb.append("YES");
			} else {
				int count = 0;
				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') {
							count += 1;
						}

					}
					if (!can)
						break;
				}
				if (arr[n - 1][m - 1] != '.') {
					can = false;
				} else {
					int c = dfs(arr, n - 1, m - 1, n, m, new boolean[n][m]);
					if (c != count) {
						can = false;
					}

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

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

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

	private static int dfs(char[][] arr, int x, int y, int n, int m, boolean[][] vis) {
		vis[x][y] = true;
		int[] row = { -1, 0, 0, 1 };
		int[] col = { 0, -1, 1, 0 };
		int ans = 0;
		for (int k = 0; k < 4; k++) {
			int nx = x + row[k];
			int ny = y + col[k];
			if (nx < 0 || ny < 0 || nx > n - 1 || ny > m - 1 || arr[nx][ny] == '#' || vis[nx][ny])
				continue;
			if (arr[nx][ny] == 'G')
				ans += 1;
			ans += dfs(arr, nx, ny, n, m, vis);
		}
		return ans;
	}

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

}