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