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

public class c1 {
    public static MyScanner scan;
    public static PrintWriter out;
    public static void main(String[] args) {
        scan=new MyScanner();
        out=new PrintWriter(new BufferedOutputStream(System.out));

//        int t=1;
        int t=scan.nextInt();
        while(t-->0) {

            n=scan.nextInt();
            m=scan.nextInt();
            s=new char[n][m];
            boolean good=false,bad=false;
            ArrayList<Node> list=new ArrayList<>();
            for(int i=0;i<n;i++) {
                String temp=scan.nextLine();
                for(int j=0;j<m;j++) {
                    s[i][j]=temp.charAt(j);
                    if(s[i][j]=='B') bad=true;
                    else if(s[i][j]=='G') {
                        good=true;
                        list.add(new Node(i,j));
                    }
                }
            }

            if(!good&&!bad) out.println("YES");
            else if(bad&&!good) out.println((s[n-1][m-1]=='B')?"NO":"YES");
            else {
                if(bad) {
                    for(int i=0;i<n;i++) {
                        for(int j=0;j<m;j++) {
                            if(s[i][j]=='B') {
                                if(i-1>=0&&s[i-1][j]=='.') s[i-1][j]='#';
                                if(j-1>=0&&s[i][j-1]=='.') s[i][j-1]='#';
                                if(i+1<n&&s[i+1][j]=='.') s[i+1][j]='#';
                                if(j+1<m&&s[i][j+1]=='.') s[i][j+1]='#';
                            }
                        }
                    }
                }
                boolean ans=true;
                for(int c=0;c<list.size();c++) {
                    if(!bfs(list.get(c),new boolean[n][m])) {
                        ans=false;
                        break;
                    }
                }
                out.println((ans)?"YES":"NO");
            }
        }
        out.close();
    }

    //-----------------------------------------------------HERE---------------------------------------------------------


    static class Node implements Comparable<Node> {
        private int x,y;
        public Node(int x,int y) {
            this.x=x;
            this.y=y;
        }

        public int compareTo(Node other) {
            if(this.x==other.x) return 0;
            else if(this.x>other.x) return 1;
            else return -1;
        }

        public boolean equals(Node other) {
            return this.x==other.x&&this.y==other.y;
        }
    }

    public static char[][] s;
    public static int n,m;

    public static boolean bfs(Node parent,boolean[][] visited) {
        Queue<Node> que=new LinkedList<>();
        visited[parent.x][parent.y]=true;
        que.add(parent);
        while(que.size()>0) {
            int size=que.size();
            while(size-->0) {
                Node tempdes=que.poll();
                int x=tempdes.x,y=tempdes.y;
                visited[x][y]=true;
                if(x==n-1&&y==m-1) return true;
                if(x-1>=0&&s[x-1][y]!='#'&&visited[x-1][y]!=true) que.add(new Node(x-1,y));
                if(y-1>=0&&s[x][y-1]!='#'&&visited[x][y-1]!=true) que.add(new Node(x,y-1));
                if(x+1<n&&s[x+1][y]!='#'&&visited[x+1][y]!=true) que.add(new Node(x+1,y));
                if(y+1<m&&s[x][y+1]!='#'&&visited[x][y+1]!=true) que.add(new Node(x,y+1));
            }
        }
        return false;
    }

    //------------------------------------------------------------------------------------------------------------------

    //util
    public static int gcd(int a, int b) {
        if (b == 0)
            return a;
        if (a == 0)
            return b;
        return (a > b) ? gcd(a % b, b) : gcd(a, b % a);
    }

    public static int lcm(int a, int b) {
        return a * b / gcd(a, b);
    }

    public static ArrayList<Integer> getPrimes(int n) {
        boolean prime[]=new boolean[n+1];
        Arrays.fill(prime,true);
        for (int p=2;p*p<=n;p++) {
            if (prime[p]) {
                for (int i=p*2;i<=n;i+=p) {
                    prime[i]=false;
                }
            }
        }
        ArrayList<Integer> primeNumbers=new ArrayList<Integer>();
        for (int i = 2; i <= n; i++) {
            if (prime[i]) {
                primeNumbers.add(i);
            }
        }
        return primeNumbers;
    }

    public static boolean isPrime(int a) {
        if (a == 0 || a == 1) {
            return false;
        }
        if (a == 2) {
            return true;
        }
        for (int i = 2; i < Math.sqrt(a) + 1; i++) {
            if (a % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static ArrayList<Integer> getDivisors(int n) {
        ArrayList<Integer> div = new ArrayList<Integer>();
        for (int i=1;i*i<=n;i++) {
            if (n%i==0) {
                div.add(i);
                if (n/i!=i)
                    div.add(n/i);
            }
        }
        return div;
    }

    //scanner
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}