import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class d extends PrintWriter{
    static BufferedReader s = new BufferedReader(new InputStreamReader(System.in));
    // static Scanner s=new Scanner(System.in);
    d() { super(System.out); }
    public static void main(String[] args) throws IOException{
        d d1=new d();d1.main();d1.flush();

    }char[] op;int[] ii,jj;int cnt;
    void main() throws IOException {
        StringBuilder sb = new StringBuilder();
        PrintWriter out = new PrintWriter(System.out);
         String[] s1=s();
         int t=i(s1[0]);
         while(t-->0){
             String[] s2=s();
             int n=i(s2[0]);int m=i(s2[1]);
             char[][] a=new char[n][m];
             for(int i=0;i<n;i++){
                 a[i]=s()[0].toCharArray();
             }flag=0;int[][] vis=new int[n][m];
             count=1;
             for(int i=0;i<n;i++){
                 for(int j=0;j<m;j++){
                     if(a[i][j]=='G'&&vis[i][j]==0){
                         hi=0;
                         dfs(a,vis,i,j,n,m);count++;
                         if(hi==0) {
                             flag=1;}
                     }
                 }
             }
             if(flag==0){
                 if(a[n-1][m-1]=='B') flag=1;
                 if(n-2>=0&&a[n-2][m-1]=='B') flag=1;
                 if(m-2>=0&&a[n-1][m-2]=='B') flag=1;
                 if(flag==1) System.out.println("NO");else
                 System.out.println("YES");
             }else System.out.println("NO");
         }

    }int flag=0;int hi=0;int count=1;
    void dfs(char[][] a,int[][] vis,int i,int j,int n,int m){
        vis[i][j]=count;

        if(i-1>=0&&a[i-1][j]=='B'){
           return;
        }
        if(i+1<n&&a[i+1][j]=='B'){
            ;return;
        }
        if(j+1<m&&a[i][j+1]=='B'){
            ;return;
        }
        if(j-1>=0&&a[i][j-1]=='B'){
            ;return;
        }
        if(i==n-1&&j==m-1){hi=1; return;}
        if(i-1>=0&&(a[i-1][j]=='.'||a[i-1][j]=='G')&&vis[i-1][j]==0) {
             dfs(a,vis,i-1,j,n,m);
        }else if(i-1>=0&&(a[i-1][j]=='.'||a[i-1][j]=='G')&&vis[i-1][j]>0&&vis[i-1][j]!=count) hi=1;

        if(i+1<n&&(a[i+1][j]=='.'||a[i+1][j]=='G')&&vis[i+1][j]==0) {
            dfs(a,vis,i+1,j,n,m);
        }else if(i+1<n&&(a[i+1][j]=='.'||a[i+1][j]=='G')&&vis[i+1][j]>0&&vis[i+1][j]!=count) hi=1;
        if(j-1>=0&&(a[i][j-1]=='.'||a[i][j-1]=='G')&&vis[i][j-1]==0) {
            dfs(a,vis,i,j-1,n,m);
        }else if(j-1>=0&&(a[i][j-1]=='.'||a[i][j-1]=='G')&&vis[i][j-1]>0&&vis[i][j-1]!=count) hi=1;
        if(j+1<m&&(a[i][j+1]=='.'||a[i][j+1]=='G')&&vis[i][j+1]==0) {
            dfs(a,vis,i,j+1,n,m);
        }else if(j+1<m&&(a[i][j+1]=='.'||a[i][j+1]=='G')&&vis[i][j+1]>0&&vis[i][j+1]!=count) hi=1;
        }
    static String[] s() throws IOException {

        return s.readLine().trim().split("\\s+");
    }

    static int i(String ss) {
        return Integer.parseInt(ss);
    }
    static long l(String ss) {
        return Long.parseLong(ss);
    }
}
class node implements Comparator<node>{
    int ver,val;
    public node(){}
    public node(int ver,int val) {
        this.ver=ver;this.val=val;
    }public int compare(node n1,node n2){
       return n1.val-n2.val;
    }
}

class Student12 {
    int  l;long r;
    public Student12(int l, long r) {
        this.l = l;
        this.r = r;
    }

    public String toString()
    {
        return this.l+" ";
    }
}
class Sortbyroll12 implements Comparator<Student12> {

    public int compare(Student12 a, Student12 b){
        if(a.r<b.r) return 1;else if(a.r==b.r) return 0;else return -1;// a.r-b.r;
      /*  if(b.r<a.r) return -1;
        else if(b.r==a.r) return 0;
        return 1;*/

        //   return b.r-a.r;
       /*
       if(b.l<a.l) return -1;
       else if(b.l==a.l) {
           return b.r-a.r;
       }
       return 1;*/
        //        return b.r- a.r;
        //        return (int) a.l-(int) b.l;
         /*   if(a.r<b.r) return -1;
            else if(a.r==b.r){
                if(a.r==b.r){
                    return 0;
                }
                if(a.r<b.r) return -1;
                return 1;}
            return 1;  */}
}
class Node1 implements Comparator<Node1>{
    int node;long val;
    public  Node1(){}
    public  Node1(int node,long val){
        this.node=node;this.val=val;
    }
    @Override
    public int compare(Node1 a,Node1 b){
        if(a.val<b.val) return -1;
        if(a.val==b.val) return 0;
        {
            return 1;
        }
    }
}
