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.*;
import java.util.*;


public class D {

    static class Pair<U extends Comparable<U>, V extends Comparable<V>>
            implements Comparable<Pair<U,V>>{

        public final U a;
        public final V b;

        private Pair(U a, V b) {
            this.a = a;
            this.b = b;
        }

        @Override
        public boolean equals(Object o) {
            if (this == o)
                return true;
            if (o == null || getClass() != o.getClass())
                return false;

            Pair<?, ?> pair = (Pair<?, ?>) o;
            if (!a.equals(pair.a))
                return false;
            return b.equals(pair.b);
        }

        @Override
        public int hashCode() {
            return 31 * a.hashCode() + b.hashCode();
        }

        @Override
        public String toString() {
            return "(" + a + ", " + b + ")";
        }

        @Override
        public int compareTo(Pair<U, V> o) {
            if(this.a.equals(o.a)){
                return getV().compareTo(o.getV());
            }
            return getU().compareTo(o.getU());
        }
        private U getU() {
            return a;
        }
        private V getV() {
            return b;
        }
    }

    static BufferedReader inp = new BufferedReader(new InputStreamReader(System.in));
    static BufferedWriter out = new BufferedWriter(new OutputStreamWriter(System.out));
    static ArrayList<Integer> arrayList;
    static int count = 0;
    static String[][] matrix;
    static ArrayList<Pair<Integer,Integer>> list;
    public static void main(String[] args) throws IOException {


        int t = Integer.parseInt(inp.readLine());
        while (t-->0){
            ans = true;
            String[] s1 = inp.readLine().split(" ");
            int row = Integer.parseInt(s1[0]);
            int col = Integer.parseInt(s1[1]);

            count = 0;

            matrix = new String[row][col];
            list = new ArrayList<>();

            for(int i=0;i<row;i++){
                s1 = inp.readLine().split("");
                for(int j=0;j<col;j++){
                    matrix[i][j] = s1[j];
                    if(s1[j].equals("B")){
                        list.add(new Pair<>(i,j));
                    }
                    if(s1[j].equals("G")){
                        count++;
                    }
                }
            }


            DFS(matrix,col,row);
//            System.out.println();
//            System.out.println(countGGGGG);
            DFS(row,col);

            //print(matrix);
            if(matrix[row-1][col-1].equals("B")){
                ans = false;
            }

            if(matrix[row-1][col-1].equals("#") && count>0){
                ans = false;
            }

            if(ans && countGGGGG ==count){
                out.write("Yes"+"\n");

            }
            else{
                out.write("No"+"\n");
            }



        }


        out.flush();



    }

    static boolean[][] visited1;
    static int countGGGGG = 0;

    static void DFS(int row,int col){
        countGGGGG = 0;
        visited1 = new boolean[row][col];
        DFSutil(col,row,row-1,col-1);

    }

    static void DFSutil(int col,int row,int i,int j){
        visited[i][j] = true;
        if(matrix[i][j].equals("G")){
            countGGGGG++;
        }

        if(j+1<col && (matrix[i][j+1].equals(".") || matrix[i][j+1].equals("G")) && !visited[i][j+1]){
            DFSutil(col,row,i,j+1);
        }

        if(i+1<row && (matrix[i+1][j].equals(".")|| matrix[i+1][j].equals("G"))&& !visited[i+1][j]){
            DFSutil(col,row,i+1,j);
        }

        if(j-1>=0 && (matrix[i][j-1].equals(".") || matrix[i][j-1].equals("G"))&& !visited[i][j-1]){
            DFSutil(col,row,i,j-1);
        }

        if(i-1>=0 && (matrix[i-1][j].equals(".")|| matrix[i-1][j].equals("G"))&& !visited[i-1][j]){
            DFSutil(col,row,i-1,j);
        }

    }

    static boolean ans = true;
    static boolean[][] visited;// = new boolean[row][col];
    static void DFS(String[][] matrix,int col,int row){
        visited = new boolean[row][col];
        for(int i=0;i<list.size();i++){
            Pair<Integer,Integer> pair = list.get(i);
            if(!visited[pair.a][pair.b]){
                DFSutil(matrix,col,row,pair.a,pair.b);
            }
        }

    }

    static void DFSutil(String[][] matrix,int col,int row,int i,int j){
        visited[i][j] = true;
        //System.out.println(i+" "+j);
        if(j+1<col && matrix[i][j+1].equals("B") && !visited[i][j+1]){
            DFSutil(matrix,col,row,i,j+1);
        }

        if(i+1<row && matrix[i+1][j].equals("B")&& !visited[i+1][j]){
            DFSutil(matrix,col,row,i+1,j);
        }

        if(j-1>=0 && matrix[i][j-1].equals("B")&& !visited[i][j-1]){
            DFSutil(matrix,col,row,i,j-1);
        }

        if(i-1>=0 && matrix[i-1][j].equals("B")&& !visited[i-1][j]){
            DFSutil(matrix,col,row,i-1,j);
        }

        if(j+1<col && matrix[i][j+1].equals("G")){
            ans = false;
        }
        else if(j+1<col && matrix[i][j+1].equals(".")){
            matrix[i][j+1] = "#";
        }
        if(i+1<row && matrix[i+1][j].equals("G")){
            ans = false;
        }
        else if(i+1<row && matrix[i+1][j].equals(".")){
            matrix[i+1][j] = "#";
        }

        if(j-1>-1 && matrix[i][j-1].equals("G")){
            ans = false;
        }
        else if(j-1>-1 && matrix[i][j-1].equals(".")){
            matrix[i][j-1] = "#";
        }

        if(i-1>-1 && matrix[i-1][j].equals("G")){
            ans = false;
        }
        else if(i-1>-1 && matrix[i-1][j].equals(".")){
            matrix[i-1][j] = "#";
        }


    }

    static void solve(int a,int b)throws IOException{
        if(count>10){
            return;
        }
        count++;


        int mid = (a+b)/2;

        out.write("? "+(b-a+1)+"");
        for(int i=a;i<=b;i++){
            out.write(" "+i);
        }
        out.write("\n");
        out.flush();
        int c = Integer.parseInt(inp.readLine());
        if(c!=-1){
            arrayList.add(c);
        }

            if(mid!=a) {
                solve(a, mid);
            }
            if(mid!=b) {
                solve(mid+1, b);
            }



    }


    static void print(int[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(int[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
    static void print(boolean[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(boolean[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
    static void print(long[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(long[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
    static void print(String[] array){
        for(int j=0;j<array.length;j++){
            System.out.print(array[j]+" ");
        }
        System.out.println();
    }
    static void print(String[][] array){
        for(int i=0;i< array.length;i++) {
            for (int j = 0; j < array[0].length; j++) {
                System.out.print(array[i][j] + " ");
            }
            System.out.println();
        }
    }
}