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:

// Spaghetti code
import java.io.*;
import java.math.*;
import java.util.*;

public class Main {
    static int mod=(int)(1e9+7);
    static int totalG2=0;
    static boolean possible=true;
    static PrintWriter pw;
    static class FastReader
    {
        private InputStream mIs;private byte[] buf = new byte[1024];private int curChar,numChars;public FastReader() { this(System.in); }public FastReader(InputStream is) { mIs = is;}
        public int read() {if (numChars == -1) throw new InputMismatchException();if (curChar >= numChars) {curChar = 0;try { numChars = mIs.read(buf);} catch (IOException e) { throw new InputMismatchException();}if (numChars <= 0) return -1; }return buf[curChar++];}
        public String nextLine(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isEndOfLine(c));return res.toString() ;}
        public String next(){int c = read();while (isSpaceChar(c)) c = read();StringBuilder res = new StringBuilder();do {res.appendCodePoint(c);c = read();}while (!isSpaceChar(c));return res.toString();}
        public long l(){int c = read();while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }long res = 0; do{ if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read();}while(!isSpaceChar(c));return res * sgn;}
        public int i(){int c = read() ;while (isSpaceChar(c)) c = read();int sgn = 1;if (c == '-') { sgn = -1 ; c = read() ; }int res = 0;do{if (c < '0' || c > '9') throw new InputMismatchException();res *= 10 ; res += c - '0' ; c = read() ;}while(!isSpaceChar(c));return res * sgn;}
        public double d() throws IOException {return Double.parseDouble(next()) ;}
        public boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; }
        public boolean isEndOfLine(int c) { return c == '\n' || c == '\r' || c == -1; }
        public void scanIntArr(int [] arr){ for(int li=0;li<arr.length;++li)arr[li]=i();}
        public void scanIntIndexArr(int [] arr){ for(int li=0;li<arr.length;++li){ arr[li]=i()-1;}}
        public void printIntArr(int [] arr){ for(int li=0;li<arr.length;++li)pw.print(arr[li]+" ");pw.println();}
        public void printLongArr(long [] arr){ for(int li=0;li<arr.length;++li)pw.print(arr[li]+" ");pw.println();}
        public void scanLongArr(long [] arr){for (int i=0;i<arr.length;++i){arr[i]=l();}}
        public void shuffle(int [] arr){ for(int i=arr.length;i>0;--i) { int r=(int)(Math.random()*i); int temp=arr[i-1]; arr[i-1]=arr[r]; arr[r]=temp; }}
        public int swapIntegers(int a,int b){return a;} //Call it like this: a=swapIntegers(b,b=a)
        public int findMax(int [] arr){return Arrays.stream(arr).sum();}

    }

    public static void main(String[] args) throws IOException {
        FastReader fr = new FastReader();
        pw = new PrintWriter(System.out);

     /*
inputCopy
6
1 1
.
1 2
G.
2 2
#B
G.
2 3
G.#
B#.
3 3
#B.
#..
GG.
2 2
#B
B.
outputCopy
Yes
Yes
No
No
Yes
Yes

1
5 5
##B##
..B#G
#.#G.
BB#..
BBB#.
    */
        //Press Ctrl+Win+Alt+L for reformatting indentation
        int t = fr.i();
        outer:for (int ti = 0; ti < t; ++ti) {
            int n=fr.i(),m=fr.i();
            char [][] str=new char[n][m];
            for(int ni=0;ni<n;++ni)str[ni]=fr.nextLine().toCharArray();

            int totalG=0;
            for(int ni=0;ni<n;++ni)
                for(int mi=0;mi<m;++mi)
                    if(str[ni][mi]=='G')
                        ++totalG;
            if(totalG==0){
                pw.println("YES");
                continue outer;
            }
            possible=true;
            for(int ni=0;ni<n;++ni){
                for(int j=0;j<m;++j){
                    if(str[ni][j]=='B'){
                        if(ni>0){
                            if(str[ni-1][j]=='.')
                                str[ni-1][j]='#';
                            else if(str[ni-1][j]=='G')
                                possible=false;
                        }
                        if(ni+1<n){
                            if(str[ni+1][j]=='.')
                                str[ni+1][j]='#';
                            else if(str[ni+1][j]=='G')
                                possible=false;
                        }
                        if(j>0){
                            if(str[ni][j-1]=='.')
                                str[ni][j-1]='#';
                            else if(str[ni][j-1]=='G')
                                possible=false;
                        }
                        if(j+1<m){
                            if(str[ni][j+1]=='.')
                                str[ni][j+1]='#';
                            else if(str[ni][j+1]=='G')
                                possible=false;
                        }
                        if(!possible){
                            pw.println("NO");
                            continue outer;
                        }
                    }
                }
            }
            //for(char [] arr:str)System.err.println(String.valueOf(arr));
            totalG2=0;
            possible=true;
            boolean [][] visited=new boolean[n][m];
            DFS(n-1,m-1,visited,str);
            if(possible)
                pw.println(totalG==totalG2?"YES":"NO");
            else
                pw.println("NO");
        }
        pw.flush();
        pw.close();
    }

    private static void DFS(int i, int j, boolean[][] visited, char[][] str) {
        if(visited[i][j] || !possible)
            return;
        //System.err.println("i="+i+" j="+j);
        if(str[i][j]=='B'){
            possible=false;
            return;
        }else if(str[i][j]=='G'){
            ++totalG2;
        }else if(str[i][j]=='#'){
            return;
        }
        visited[i][j]=true;
        if(i-1>=0 && !visited[i-1][j])
            DFS(i-1,j,visited,str);
        if(i+1<visited.length && !visited[i+1][j])
            DFS(i+1,j,visited,str);
        if(j-1>=0 && !visited[i][j-1])
            DFS(i,j-1,visited,str);
        if(j+1<visited[i].length && !visited[i][j+1])
            DFS(i,j+1,visited,str);
    }
}