import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.nio.Buffer;
import java.util.*;

public class ssss {
    static boolean ans;
    public static void main(String[] args){
        try {
            PrintWriter out=new PrintWriter(System.out,true);
            BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
            int t=Integer.parseInt(br.readLine());
            for(int i=0;i<t;i++){
                String[] ss=br.readLine().split(" ");
                int n = Integer.parseInt(ss[0]);
                int m = Integer.parseInt(ss[1]);
                char[][] maze = new char[n][m];
                for(int j=0;j<n;j++){
                    String str=br.readLine();
                    for(int k=0;k<m;k++){
                        maze[j][k]=str.charAt(k);
                    }
                }
                boolean bb=false;
                int b=0,g=0;
                for(int j=0;j<n;j++){
                    for(int k=0;k<m;k++){
                        if(maze[j][k]=='B'){
                            b++;
                            int[] x=new int[]{1,0,-1,0};
                            int[] y=new int[]{0,1,0,-1};
                            for(int p=0;p<4;p++){
                                if(j+x[p]>=0 && j+x[p]<n && k+y[p]>=0 && k+y[p]<n){
                                    if(maze[j+x[p]][k+y[p]]=='G'){
                                        bb=true;
                                        break;
                                    }else if(maze[j+x[p]][k+y[p]]=='.'){
                                        maze[j+x[p]][k+y[p]]='#';
                                    }
                                }
                            }
                        }else if(maze[j][k]=='G'){
                            g++;
                        }
                    }
                    if(bb){
                        break;
                    }
                }
                if(bb){
                    out.println("NO");
                    continue;
                }
                if(g==0){
                    out.println("YES");
                    continue;
                }

                Queue<int[]> q=new ArrayDeque<>();
                for(int j=0;j<n;j++){
                    for(int k=0;k<m;k++){
                        if(maze[j][k]=='G'){
                            q.add(new int[]{j,k});
                        }
                    }
                }
                bb=false;
                while(q.size()>0){
                    boolean[][] vis=new boolean[n][m];
                    int[] a=q.poll();
                    int x=a[0],y=a[1];
                    ans=false;
                    dfs(maze,vis,x,y,n,m);
                    if(!ans){
                        bb=true;
                        break;
                    }
                }
                if(bb) {
                    out.println("NO");
                }else{
                    out.println("YES");
                }
            }
            out.close();
        } catch (Exception e) {
            System.out.println("kkkk "+ e.getMessage());
        }

    }
    static void dfs(char[][] maze,boolean[][] vis,int i,int j,int n,int m){
        if(i<0 || i>=n || j<0 || j>=m || vis[i][j]){
            return;
        }
        if(maze[i][j]=='#'){
            return;
        }
        if(i==n-1 && j==m-1){
            ans=true;
            return;
        }
        vis[i][j]=true;
        dfs(maze,vis,i+1,j,n,m);
        dfs(maze,vis,i,j+1,n,m);
        dfs(maze,vis,i-1,j,n,m);
        dfs(maze,vis,i,j-1,n,m);
    }
}
