

import java.util.Scanner;
import java.util.Stack;

public class Main {
    public static int dirr[][] = {{1,0},{0,1},{0,-1},{-1,0}};
    public static boolean possible;
    public static void main(String[] args) {
	// write your code here
        q1365D();
    }

    public static void q1365D(){
        Scanner sc = new Scanner(System.in);
        int t = sc.nextInt();
        for(int i=0;i<t;i++){
            possible = true;
            int n = sc.nextInt();
            int m = sc.nextInt();
            Integer[][] graph = new Integer[n+1][m+1];
            Corrd[][] corrds = new Corrd[n+1][m+1];
            if(i==61) {
                  System.out.println(n+" "+m);
            }
            for(int j=0;j<n;j++){
                String str = sc.next();
                if(i==61) {
                     System.out.println(str);
                }
                for(int k=0;k<m;k++){
                    graph[j][k] = (int)str.charAt(k);
                  //  System.out.println(graph[j][k]);
                    corrds[j][k] = new Corrd(j,k);
                }
            }
            dfs(n-1,m-1,n,m,graph,corrds);
            if(!possible){
                System.out.println("NO");
                continue;
            }
            dfs(n-1,m-1,n,m,graph,corrds);
            for(int j=0;j<n;j++){
                for(int k=0;k<m;k++){
                   // System.out.print((char)((int)graph[j][k]));
                    if(graph[j][k]=='G'){
                      //  System.out.print(corrds[j][k].color);
                        if(corrds[j][k].color<2){
                          //  System.out.print("Mee"+corrds[j][k].color);
                            possible = false;
                            break;
                        }
                    }
                }
               // System.out.println();
            }
            System.out.println(possible?"YES":"NO");
        }
    }
    public static void dfs(int x,int y,int maxx,int maxy,Integer[][] graph,Corrd[][] corrds){
        Stack<Corrd> st = new Stack<Corrd>();
        if(graph[x][y]=='#'){
            return;
        }
        st.push(corrds[x][y]);
        corrds[x][y].color++;
        while(!st.empty()){
            Corrd p = st.pop();
          //  System.out.println(p.x+" "+p.y);
            for(int i=0;i<4;i++){
                int nx = p.x+dirr[i][0];
                int ny = p.y+dirr[i][1];
                if(nx>=0 && nx<maxx && ny>=0 && ny<maxy && corrds[nx][ny].color==0){
                    if(!(graph[nx][ny]=='#')) {
                        if(graph[nx][ny]=='B' && (graph[p.x][p.y]=='.')){
                            graph[p.x][p.y] = (int)'#';
                            break;
                        }
                        else{
                            if(graph[nx][ny]=='B' && graph[p.x][p.y]=='G'){
                                possible = false;
                                break;
                            }
                            else {
                                corrds[nx][ny].color++;
                                st.push(corrds[nx][ny]);
                            }
                        }
                    }
                }
                else if(nx>=0 && nx<maxx && ny>=0 && ny<maxy && corrds[nx][ny].color==1){
                    if(!(graph[nx][ny]=='#')){
                        corrds[nx][ny].color++;
                        st.push(corrds[nx][ny]);
                    }
                }

            }
        }

    }

    public static class Corrd{
        int x;
        int y;
        int color;
        Corrd(int x,int y){
            this.x = x;
            this.y = y;
            this.color =0;
        }
    }
}
