import java.util.Scanner;

public class p1365D {
    static int n,m,dir[][]={{1,0},{-1,0},{0,1},{0,-1}};
    static boolean[]vis[];
    static char[]a[];
    public static void main(String[] args) throws Exception {
        Scanner sc=new Scanner(System.in);
        StringBuilder sb=new StringBuilder();
        l:for(int t=sc.nextInt();t-->0;sb.append("\n")) {
            n=sc.nextInt();m=sc.nextInt();
            vis=new boolean[n][m];
            a=new char[n][m];
            for(int i=0;i<n;i++) a[i]=sc.next().toCharArray();
            replace();
            bfs();
            for(int i=0;i<n;i++)
                for(int j=0;j<m;j++) 
                    if((a[i][j]=='G'&&!vis[i][j])||(a[i][j]=='B'&&vis[i][j]))
                        {sb.append("NO");continue l;}
            sb.append("YES");
        }
        System.out.println(sb);
    }
    static void replace() {
        for(int i=0;i<n;i++) {
            for(int j=0;j<m;j++) {
                if(a[i][j]=='B') {
                    for(int k=0;k<4;k++) {
                        int r=i+dir[k][0],c=j+dir[k][1];
                        if(r<0||c<0||r>=n||c>=m||a[r][c]!='.') continue;
                        a[r][c]='#';
                    }
                }
            }
        }
    }
    static void bfs() {
        queue q=new queue();
        if(a[n-1][m-1]=='.') {
            q.push(new pair(n-1,m-1));
            vis[n-1][m-1]=true;
        }
        while(!q.empty()) {
            pair z=q.pop();
            for(int i=0;i<4;i++) {
                int r=z.f+dir[i][0],c=z.s+dir[i][1];
                if(r<0||c<0||r>=n||c>=m||vis[r][c]||a[r][c]=='#') continue;
                q.push(new pair(r,c));
                vis[r][c]=true;
            }
        }
    }
    static class queue{
        static class node{
            pair e;
            node next;
            node(pair d,node n){e=d;next=n;}
        }
        node head,tail;
        void push(pair e) {
            if(head==null) tail=head=new node(e,null);
            else tail=tail.next=new node(e,null);
        }
        pair pop() {
            pair e=head.e;
            head=head.next;
            return e;
        }
        boolean empty() {return head==null;}
    }
    
    static class pair{
        int f,s;
        pair(int... a){f=a[0];s=a[1];}
    }
}