import java.io.*;
import java.util.*;
 

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Unstoppable solver = new Unstoppable();
		int t=in.nextInt();
		while(t-->0)
        solver.solve(in, out);
        out.close();
    }
 
    static class Unstoppable { static int n,m;
        static boolean visit[][];
        public static void dfs(char ch[][],boolean visit[][],Stack<Integer> r,Stack<Integer> c){
                int i=r.pop(); int j=c.pop();
                if(i-1>=0&&ch[i-1][j]!='#'&&visit[i-1][j]==false) { visit[i-1][j]=true; r.add(i-1); c.add(j); } 
                if(i+1<n&&ch[i+1][j]!='#'&&visit[i+1][j]==false) { visit[i+1][j]=true; r.add(i+1); c.add(j); } 
                if(j-1>=0&&ch[i][j-1]!='#'&&visit[i][j-1]==false) { visit[i][j-1]=true; r.add(i); c.add(j-1); } 
                if(j+1<m&&ch[i][j+1]!='#'&&visit[i][j+1]==false) { visit[i][j+1]=true; r.add(i); c.add(j+1); } 
                if(!r.isEmpty()) dfs(ch,visit,r,c); 
        }
        public void solve(InputReader in, PrintWriter out) {
            n=in.nextInt();
            m=in.nextInt();
        char ch[][]=new char[n][m];
        for(int i=0;i<n;i++){
          ch[i]=in.next().toCharArray(); 
        }
        
        for(int i=0;i<n;i++){
          for(int j=0;j<m;j++){
            if(ch[i][j]=='B')
            {
                if(i-1>=0&&ch[i-1][j]=='.') ch[i-1][j]='#';
                if(i+1<n&&ch[i+1][j]=='.') ch[i+1][j]='#';
                if(j-1>=0&&ch[i][j-1]=='.') ch[i][j-1]='#';
                if(j+1<m&&ch[i][j+1]=='.') ch[i][j+1]='#';
            }
          } 
        }
        int flag=0;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                visit=new boolean[n][m];
                Stack<Integer> r=new Stack<Integer>(); r.add(i);
                Stack<Integer> c=new Stack<Integer>(); c.add(j);
                if(ch[i][j]=='G'){ dfs(ch,visit,r,c); if(visit[n-1][m-1]==false){ flag=1; break; } }
            }
        }
        if(flag==1) out.println("NO");
        else out.println("YES");
      }
    }

 
    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;
 
        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }
 
        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }
        public long nextLong(){
            return Long.parseLong(next());
        }
        public int nextInt() {
            return Integer.parseInt(next());
        }
 
    }
}
   