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.io.*;

public class File {
    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            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());
        }
    }	
	
    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
		
		
		
		
		int T = sc.nextInt();
		
		for (int t = 1; t <= T; t++) {
			int m = sc.nextInt();
			int n = sc.nextInt();
			
			char[][] grid = new char[m][n];
			
			LinkedList<int[]> goods = new LinkedList();
			LinkedList<int[]> bads = new LinkedList();
			
			for (int r = 0; r < m; r++) {
				String row = sc.next();
				
				for (char c = 0; c < n; c++) {
					grid[r][c] = row.charAt(c);
					
					if (grid[r][c] == 'G') {
						goods.add(new int[] {r, c});
					}
					else if (grid[r][c] == 'B') {
						bads.add(new int[] {r, c});
					}
				}							
			}
			
			boolean isPossible = true;
			// If there are no goods, we just block off the exit.
			// Only care that goods can escape, after blocking bads.
			if (goods.size() > 0) {
				for (int[] pair : bads) {
					int r = pair[0];
					int c = pair[1];
					
					if (grid[r][c] == 'B') {
						if (!DFS(grid, r, c)) {
							isPossible = false;
						}
					}
				}
				
				if (isPossible) {
					// How many goods can we reach from the exit
					int count = BFS(grid, m-1, n-1);
						
					if (count != goods.size()) {
						isPossible = false;
					}
				}
			}
			
			if (isPossible) {
				out.println("Yes");
			}
			else {
				out.println("No");
			}
		}
		
		
		out.close();
	}
	
	public static int[][] dirs = new int[][] {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
	
	// Return true if no 'G' encountered.
	public static boolean DFS(char[][] grid, int r, int c) {
		if (r < 0 || r >= grid.length || c < 0 || c >= grid[0].length) {
			return true;
		}
		
		boolean noGoods = true;
		grid[r][c] = '#';
		
		for (int[] dir : dirs) {
			int nextR = r + dir[0];
			int nextC = c + dir[1];
				
			if (nextR >= 0 && nextR < grid.length && nextC >= 0 && nextC < grid[0].length) {
				if (grid[nextR][nextC] == 'B') {
					if (!DFS(grid, nextR, nextC)) {
						noGoods = false;
					}
				}
				else if (grid[nextR][nextC] == 'G') {
					noGoods = false;
					break;
				}
				else if (grid[nextR][nextC] == '.') {
					grid[nextR][nextC] = '#';
				}
			}
		}
		
		return noGoods;
	}
	
	// Return how many 'G' we can reach.
	public static int BFS(char[][] grid, int r, int c) {
	    if (grid[r][c] == '#') return -1;
	    
		LinkedList<int[]> queue = new LinkedList();
		queue.add(new int[] {r, c});
		grid[r][c] = '#';
		int count = 0;
		
		while (!queue.isEmpty()) {
			int[] curr = queue.removeFirst();
			
			for (int[] dir : dirs) {
				int nextR = curr[0] + dir[0];
				int nextC = curr[1] + dir[1];
				
				if (nextR >= 0 && nextR < grid.length && nextC >= 0 && nextC < grid[0].length) {
					if (grid[nextR][nextC] != '#') {
						if (grid[nextR][nextC] == 'G') {
							count++;
						}
						
						grid[nextR][nextC] = '#';
						queue.addLast(new int[] {nextR, nextC});
					}
				}
			}
		}
		
		return count;
	}
}