import java.io.*;
import java.util.*;
public class Main {
    static PrintWriter pw;
    static Scanner sc;
    static char[][] arr;
    static Boolean[][] access;
    public static long gcf(long x, long y) {
        while(x%y!=0 && y%x!=0) {
            if(x>y)
                x%=y;
            else
                y%=x;
        }
        return x>y? y:x;
    }
    static int ceildiv(int x, int y){
        return x%y==0? x/y: x/y+1;
    }
    static long pow(long a, long pow){
        long ans=1;
        while(pow>0){
            if((pow&1)==1)
                ans*=a;
            a*=a;
            pow>>=1;
        }
        return ans;
    }
    static int prime(int x) {
        for(int i=2; i<=x/i; i++) {
            if(x%i==0)
                return x/i;
        }
        return 1;
    }
    static boolean valid(int i, int j){
        return i<arr.length && i>=0 && j<arr[0].length && j>=0;
    }
    static void dfs(int i, int j, boolean[][] visit){
        visit[i][j]=true;
        for(int k=0; k<4; k++){
            if(valid(i+dx[k], j+dy[k]) && arr[i+dx[k]][j+dy[k]]!='#' && !visit[i+dx[k]][j+dy[k]]){
                if(access[i+dx[k]][j+dy[k]]==null) {
                    dfs(i + dx[k], j + dy[k], visit);
                }
                if(access[i+dx[k]][j+dy[k]]==true){
                    access[i][j]=true;
                    return;
                }
            }
        }
        access[i][j]=false;
    }
    static int[] dx={1,-1,0,0};
    static int[] dy={0,0,1,-1};
    static boolean good(){
        int n=arr.length, m=arr[0].length;
        boolean[][] visit=new boolean[n][m];
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(arr[i][j]=='G') {
                    if(!visit[i][j])
                        dfs(i, j, visit);
                    if(!access[i][j])
                        return false;
                }
            }
        }
        return true;
    }
    static boolean bad(){
        int n=arr.length, m=arr[0].length;
        boolean[][] visit=new boolean[n][m];
        for(int i=0; i<n; i++){
            for(int j=0; j<m; j++){
                if(arr[i][j]=='B') {
                    if(!visit[i][j])
                        dfs(i, j, visit);
                    if(access[i][j])
                        return false;
                }
            }
        }
        return true;
    }
    public static void main(String[] args) throws Exception {
        sc = new Scanner(System.in);
        pw = new PrintWriter(System.out);
        int tc=sc.nextInt();
        while(tc-->0){
            int n=sc.nextInt(), m=sc.nextInt();
            arr=new char[n][];
            for(int i=0; i<n; i++)
                arr[i]=sc.nextLine().toCharArray();
            for(int i=0; i<n; i++){
                for(int j=0; j<m; j++){
                    if(arr[i][j]=='B'){
                        if(i<n-1 && arr[i+1][j]=='.')
                            arr[i+1][j]='#';
                        if(j<m-1 && arr[i][j+1]=='.')
                            arr[i][j+1]='#';
                        if(i>0 && arr[i-1][j]=='.')
                            arr[i-1][j]='#';
                        if(j>0 && arr[i][j-1]=='.')
                            arr[i][j-1]='#';
                    }
                }
            }
            access=new Boolean[n][m];
            access[n-1][m-1]=true;
            pw.println(good() && bad()? "YES": "NO");
        }
        pw.close();
    }
    static class Scanner {
        StringTokenizer st;
        BufferedReader br;
        public Scanner(InputStream s) {
            br = new BufferedReader(new InputStreamReader(s));
        }

        public Scanner(FileReader r) {
            br = new BufferedReader(r);
        }

        public String next() throws IOException {
            while (st == null || !st.hasMoreTokens())
                st = new StringTokenizer(br.readLine());
            return st.nextToken();
        }

        public int nextInt() throws IOException {
            return Integer.parseInt(next());
        }

        public long nextLong() throws IOException {
            return Long.parseLong(next());
        }

        public String nextLine() throws IOException {
            return br.readLine();
        }

        public double nextDouble() throws IOException {
            return Double.parseDouble(next());
        }

        public int[] nextArr(int n) throws IOException {
            int[] arr = new int[n];
            for (int i = 0; i < arr.length; i++)
                arr[i] = nextInt();
            return arr;
        }
        public Integer[] nextsort(int n) throws IOException{
            Integer[] arr=new Integer[n];
            for(int i=0; i<n; i++)
                arr[i]=nextInt();
            return arr;
        }
        public boolean ready() throws IOException {
            return br.ready();
        }
    }
    static class Pair implements Comparable<Pair>{
        int x;
        int y;
        public Pair(int x, int y) {
            this.x=x;
            this.y=y;
        }
        public int hashCode() {
            return this.x*1000+this.y;
        }
        public int compareTo(Pair other) {
            if(this.y!=other.y){
                return other.y-this.y;
            }else{
                return (this.x-other.x);
            }
        }
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (this.getClass() != obj.getClass()) {
                return false;
            }
            Pair p = (Pair) obj;
            return this.x == p.x;
        }
        public boolean equal(Pair p){
            return this.x==p.x && this.y==p.y;
        }
    }
    static class tuple implements Comparable<tuple>{
        int x;int y;int z;
        public tuple(int x, int y, int z){
            this.x=x;
            this.y=y;
            this.z=z;
        }
        public int compareTo(tuple other) {
            if(this.x!=other.x)
                return this.x-other.x;
            else {
                if(this.y!=other.y)
                    return this.y-other.y;
                else
                    return this.z-other.z;
            }
        }
        public boolean equal(tuple t){
            return this.x==t.x && this.y==t.y;
        }
    }
}
