import sun.rmi.runtime.Log;

import java.io. *;
import java.util.*;
import static java.lang.Math.*;
public class Main {

    static final FastReader sc = new FastReader(System.in);
    static final PrintWriter pw = new PrintWriter(System.out);

    static int visited[];
    static ArrayList<ArrayList<Integer>> adjlist;
    static class edge implements  Comparator<edge>{
        int dest;
        int cost;

        public edge(int dest, int cost) {
            this.dest = dest;
            this.cost = cost;
        }

        @Override
        public int compare(edge o1, edge o2) {
            return o1.cost-o2.cost;
        }
    }

    static int dist[];
    static int nodesinSubtree[];
    static int color[];
    static ArrayList<Integer> res1;
    static ArrayList<Integer> res2;

    static class Graph{
        int V;
        ArrayList<ArrayList<edge>> adj;
        PriorityQueue<edge> pq;

        public Graph(int V){
            this.V = V;
            adj = new ArrayList<>(V);
            pq = new PriorityQueue<>(V,new edge(-1,-1));
            dist = new int[V];
            nodesinSubtree = new int[V];
            color = new int[V];
            Arrays.fill(color,-1);
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
                adj.add(i,new ArrayList<>());
            }
        }

        void addedge(int u, int v, int w ){
            adj.get(u).add(new edge(v,w));
            //adj.get(v).add(new edge(u,w));
        }

        void rDfs(int src, int e){
            //nodes in a subtree
            nodesinSubtree[src] = 1;
            for(int i=0; i<adj.get(src).size(); i++){
                if(adj.get(src).get(i).dest==e){
                    continue;
                }
                rDfs(adj.get(src).get(i).dest,src);
                nodesinSubtree[src]+=nodesinSubtree[adj.get(src).get(i).dest];
            }
        }

        void uBFS(int src){
            Queue<edge> q = new LinkedList<>();
            color = new int[V];
            q.add(new edge(src,0));
            color[src] = 0;
            while (!q.isEmpty()){
                int u = q.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    if(color[adj.get(u).get(i).dest]==color[u]){
                        color[adj.get(u).get(i).dest] = color[u]+1;
                        q.add(new edge(adj.get(u).get(i).dest,0));
                    }
                }
            }
        }

        int DFS(int src){
            Stack<edge> st = new Stack<>();
            boolean visited[] = new boolean[V];
            visited[src] = true;
            st.push(new edge(src,0));
            dist[src] = 0;
            color[src] = 1;
            while (!st.empty()){
                int u = st.peek().dest;
                st.pop();
                for(int i=0; i<adj.get(u).size(); i++){
                    if(color[adj.get(u).get(i).dest]==0) {
                        if (color[u] == 0) {
                            color[adj.get(u).get(i).dest] = 1;
                        } else {
                            color[adj.get(u).get(i).dest] = 0;
                        }
                        st.push(new edge(adj.get(u).get(i).dest,0));
                    }else{
                        if(color[u]==0 && color[adj.get(u).get(i).dest]==0){
                            return -1;
                        }
                        if(color[u]==1 && color[adj.get(u).get(i).dest]==1){
                            return -1;
                        }
                    }
                }
            }
            return 0;
        }
    }

/*
        void dijkstra(int src){
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
            }
            dist[src] = 0;
            pq.add(new edge(src,0));
            while (!pq.isEmpty()){
                int u = pq.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                }
            }

        }

    }

 */

    static  int I[];
    static  int  L[];
    static void LIS(int n, int arr[]){
        I = new int[n+1];
        L = new int[n];
        I[0] = Integer.MIN_VALUE;
        for(int i=1;i<=n; i++){
            I[i] = Integer.MAX_VALUE;
        }
        int lisLength = 1;

        for(int i=n-1; i>=0; i--) {
            int low = 1;
            int high = lisLength;
            int mid = 0;
            while (low < high) {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            }
            I[high] = arr[i];
            L[i] = high;
            if(lisLength<=high){
                lisLength++;
            }
        }
    }

    public static long gcd(long a, long b)
    {
        if (a == 0)
            return b;

        return gcd(b%a, a);
    }

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

    static long nCr(long n, long r)
    {
        return fact(n) / (fact(r) * fact(n - r));
    }

    // Returns factorial of n
    static long fact(long n)
    {
        long res = 1;
        for (int i = 2; i <= n; i++)
            res = (res * i)%MOD;
        return res;
    }

    static int MOD = 1000000007;
    static int power(int x, int y, int p)
    {

        // Initialize result
        int res = 1;

        // Update x if it is more than or
        // equal to p
        x = x % p;

        while (y > 0)
        {

            // If y is odd, multiply x
            // with result
            if (y % 2 == 1)
                res = (res * x) % p;

            // y must be even now
            y = y >> 1; // y = y/2
            x = (x * x) % p;
        }

        return res;
    }

    // Returns n^(-1) mod p
    static int modInverse(int n, int p)
    {
        return power(n, p-2, p);
    }

    static int nCrModPFermat(int n, int r,
                             int p)
    {

        if (r == 0)
            return 1;

        int[] fac = new int[n+1];
        fac[0] = 1;

        for (int i = 1 ;i <= n; i++)
            fac[i] = fac[i-1] * i % p;

        return (fac[n]* modInverse(fac[r], p)
                % p * modInverse(fac[n-r], p)
                % p) % p;
    }

    static int[] phi;

    static void generatePhi(int n){
        phi = new int[n+1];

        for(int i = 0; i<=n; i++){
            phi[i] = i;
        }

        for(int i=2; i<=n; i++){
            if(phi[i]==i){
                for(int j= i; j<=n; j+=i){
                    phi[j] -= (phi[j]/i);
                }
            }
        }
    }

    static int gcdCount(int n, int d){
        return phi[n/d];
    }

    static boolean prime[];

    static void sieveOfEratosthenes(int n)
    {
        prime = new boolean[n+1];
        for(int i=0;i<n;i++)
            prime[i] = true;

        for(int p = 2; p*p <=n; p++)
        {
            if(prime[p] == true)
            {
                for(int i = p*p; i <= n; i += p)
                    prime[i] = false;
            }
        }

    }

    static double Logx(double n, int x){
        return log(n)/log(x);
    }

    static boolean isPrime(long n){
        if(n<2){
            return false;
        }
        for(int i = 2; i*i<=n; i++){
            if(n%i==0){
                return false;
            }
        }
        return true;
    }

    static boolean BFS(char inp[][], int srcx, int srcy, int n, int m){

        Queue<Integer> qx = new LinkedList<>();
        Queue<Integer> qy = new LinkedList<>();
        qx.add(srcx);
        qy.add(srcy);
        boolean visited[][] = new boolean[n][m];
        while (!qx.isEmpty() && !qy.isEmpty()){
            int u = qx.poll();
            int v = qy.poll();

            for(int i = 0; i<4; i++){
                int x = u + dx[i];
                int y = v + dy[i];
                if (x > n - 1 || x < 0 || y > m - 1 || y < 0) {
                    continue;
                }
                if(inp[x][y]=='.' && !visited[x][y]){
                    visited[x][y] = true;
                    qx.add(x);
                    qy.add(y);
                }
            }
        }
        return visited[n-1][m-1];
    }
    static int dx[] = {-1,1,0,0};
    static int dy[] = {0,0,1,-1};
    public static void main(String[] args) {

        int testcase = sc.nextInt();

        while (testcase-->0) {

            int n = sc.nextInt();
            int m = sc.nextInt();

            char inp[][] = new char[n][m];

            for(int i = 0; i<n; i++){
                for(int j =0; j<m; j++){
                    inp[i][j] = sc.nextChar();
                }
            }

            for(int i = 0; i<n; i++){
                for(int j =0; j<m; j++){
                    if(inp[i][j]=='B') {
                        for (int k = 0; k < 4; k++) {
                            int x = i + dx[k];
                            int y = j + dy[k];
                            if (x > n - 1 || x < 0 || y > m - 1 || y < 0) {
                                continue;
                            }
                            if(inp[x][y]=='.'){
                                inp[x][y] = '#';
                            }
                        }
                    }
                }
            }

            boolean check = true;

            for(int i = 0; i<n; i++){
                for(int j =0; j<m; j++){
                    if(inp[i][j]=='G'){
                        check = BFS(inp,i,j,n,m);
                    }
                }
            }

            if(check){
                pw.println("Yes");
            }else{
                pw.println("No");
            }

        }
        pw.flush();

    }

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

        public int readByte(){
            if(lenbuf == -1)throw new InputMismatchException();
            if(ptrbuf >= lenbuf){
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if(lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        }
        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }
        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }
        public String next(){
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while(!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public String nextLine(){
            int b = readByte();
            StringBuilder sb = new StringBuilder();
            while(b != '\n' || b != '\r'){
                sb.appendCodePoint(b);
            }
            return sb.toString();
        }
        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
        public char[] next(int n){
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }
        public char nextChar () {
            return (char) skip();
        }
    }
}


import sun.rmi.runtime.Log;

import java.io. *;
import java.util.*;
import static java.lang.Math.*;
public class Main {

    static final FastReader sc = new FastReader(System.in);
    static final PrintWriter pw = new PrintWriter(System.out);

    static int visited[];
    static ArrayList<ArrayList<Integer>> adjlist;
    static class edge implements  Comparator<edge>{
        int dest;
        int cost;

        public edge(int dest, int cost) {
            this.dest = dest;
            this.cost = cost;
        }

        @Override
        public int compare(edge o1, edge o2) {
            return o1.cost-o2.cost;
        }
    }

    static int dist[];
    static int nodesinSubtree[];
    static int color[];
    static ArrayList<Integer> res1;
    static ArrayList<Integer> res2;

    static class Graph{
        int V;
        ArrayList<ArrayList<edge>> adj;
        PriorityQueue<edge> pq;

        public Graph(int V){
            this.V = V;
            adj = new ArrayList<>(V);
            pq = new PriorityQueue<>(V,new edge(-1,-1));
            dist = new int[V];
            nodesinSubtree = new int[V];
            color = new int[V];
            Arrays.fill(color,-1);
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
                adj.add(i,new ArrayList<>());
            }
        }

        void addedge(int u, int v, int w ){
            adj.get(u).add(new edge(v,w));
            //adj.get(v).add(new edge(u,w));
        }

        void rDfs(int src, int e){
            //nodes in a subtree
            nodesinSubtree[src] = 1;
            for(int i=0; i<adj.get(src).size(); i++){
                if(adj.get(src).get(i).dest==e){
                    continue;
                }
                rDfs(adj.get(src).get(i).dest,src);
                nodesinSubtree[src]+=nodesinSubtree[adj.get(src).get(i).dest];
            }
        }

        void uBFS(int src){
            Queue<edge> q = new LinkedList<>();
            color = new int[V];
            q.add(new edge(src,0));
            color[src] = 0;
            while (!q.isEmpty()){
                int u = q.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    if(color[adj.get(u).get(i).dest]==color[u]){
                        color[adj.get(u).get(i).dest] = color[u]+1;
                        q.add(new edge(adj.get(u).get(i).dest,0));
                    }
                }
            }
        }

        int DFS(int src){
            Stack<edge> st = new Stack<>();
            boolean visited[] = new boolean[V];
            visited[src] = true;
            st.push(new edge(src,0));
            dist[src] = 0;
            color[src] = 1;
            while (!st.empty()){
                int u = st.peek().dest;
                st.pop();
                for(int i=0; i<adj.get(u).size(); i++){
                    if(color[adj.get(u).get(i).dest]==0) {
                        if (color[u] == 0) {
                            color[adj.get(u).get(i).dest] = 1;
                        } else {
                            color[adj.get(u).get(i).dest] = 0;
                        }
                        st.push(new edge(adj.get(u).get(i).dest,0));
                    }else{
                        if(color[u]==0 && color[adj.get(u).get(i).dest]==0){
                            return -1;
                        }
                        if(color[u]==1 && color[adj.get(u).get(i).dest]==1){
                            return -1;
                        }
                    }
                }
            }
            return 0;
        }
    }

/*
        void dijkstra(int src){
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
            }
            dist[src] = 0;
            pq.add(new edge(src,0));
            while (!pq.isEmpty()){
                int u = pq.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                }
            }

        }

    }

 */

    static  int I[];
    static  int  L[];
    static void LIS(int n, int arr[]){
        I = new int[n+1];
        L = new int[n];
        I[0] = Integer.MIN_VALUE;
        for(int i=1;i<=n; i++){
            I[i] = Integer.MAX_VALUE;
        }
        int lisLength = 1;

        for(int i=n-1; i>=0; i--) {
            int low = 1;
            int high = lisLength;
            int mid = 0;
            while (low < high) {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            }
            I[high] = arr[i];
            L[i] = high;
            if(lisLength<=high){
                lisLength++;
            }
        }
    }

    public static long gcd(long a, long b)
    {
        if (a == 0)
            return b;

        return gcd(b%a, a);
    }

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

    static long nCr(long n, long r)
    {
        return fact(n) / (fact(r) * fact(n - r));
    }

    // Returns factorial of n
    static long fact(long n)
    {
        long res = 1;
        for (int i = 2; i <= n; i++)
            res = (res * i)%MOD;
        return res;
    }

    static int MOD = 1000000007;
    static int power(int x, int y, int p)
    {

        // Initialize result
        int res = 1;

        // Update x if it is more than or
        // equal to p
        x = x % p;

        while (y > 0)
        {

            // If y is odd, multiply x
            // with result
            if (y % 2 == 1)
                res = (res * x) % p;

            // y must be even now
            y = y >> 1; // y = y/2
            x = (x * x) % p;
        }

        return res;
    }

    // Returns n^(-1) mod p
    static int modInverse(int n, int p)
    {
        return power(n, p-2, p);
    }

    static int nCrModPFermat(int n, int r,
                             int p)
    {

        if (r == 0)
            return 1;

        int[] fac = new int[n+1];
        fac[0] = 1;

        for (int i = 1 ;i <= n; i++)
            fac[i] = fac[i-1] * i % p;

        return (fac[n]* modInverse(fac[r], p)
                % p * modInverse(fac[n-r], p)
                % p) % p;
    }

    static int[] phi;

    static void generatePhi(int n){
        phi = new int[n+1];

        for(int i = 0; i<=n; i++){
            phi[i] = i;
        }

        for(int i=2; i<=n; i++){
            if(phi[i]==i){
                for(int j= i; j<=n; j+=i){
                    phi[j] -= (phi[j]/i);
                }
            }
        }
    }

    static int gcdCount(int n, int d){
        return phi[n/d];
    }

    static boolean prime[];

    static void sieveOfEratosthenes(int n)
    {
        prime = new boolean[n+1];
        for(int i=0;i<n;i++)
            prime[i] = true;

        for(int p = 2; p*p <=n; p++)
        {
            if(prime[p] == true)
            {
                for(int i = p*p; i <= n; i += p)
                    prime[i] = false;
            }
        }

    }

    static double Logx(double n, int x){
        return log(n)/log(x);
    }

    static boolean isPrime(long n){
        if(n<2){
            return false;
        }
        for(int i = 2; i*i<=n; i++){
            if(n%i==0){
                return false;
            }
        }
        return true;
    }

    static boolean BFS(char inp[][], int srcx, int srcy, int n, int m){

        Queue<Integer> qx = new LinkedList<>();
        Queue<Integer> qy = new LinkedList<>();
        qx.add(srcx);
        qy.add(srcy);
        boolean visited[][] = new boolean[n][m];
        while (!qx.isEmpty() && !qy.isEmpty()){
            int u = qx.poll();
            int v = qy.poll();

            for(int i = 0; i<4; i++){
                int x = u + dx[i];
                int y = v + dy[i];
                if (x > n - 1 || x < 0 || y > m - 1 || y < 0) {
                    continue;
                }
                if(inp[x][y]=='.' && !visited[x][y]){
                    visited[x][y] = true;
                    qx.add(x);
                    qy.add(y);
                }
            }
        }
        return visited[n-1][m-1];
    }
    static int dx[] = {-1,1,0,0};
    static int dy[] = {0,0,1,-1};
    public static void main(String[] args) {

        int testcase = sc.nextInt();

        while (testcase-->0) {

            int n = sc.nextInt();
            int m = sc.nextInt();

            char inp[][] = new char[n][m];

            for(int i = 0; i<n; i++){
                for(int j =0; j<m; j++){
                    inp[i][j] = sc.nextChar();
                }
            }

            for(int i = 0; i<n; i++){
                for(int j =0; j<m; j++){
                    if(inp[i][j]=='B') {
                        for (int k = 0; k < 4; k++) {
                            int x = i + dx[k];
                            int y = j + dy[k];
                            if (x > n - 1 || x < 0 || y > m - 1 || y < 0) {
                                continue;
                            }
                            if(inp[x][y]=='.'){
                                inp[x][y] = '#';
                            }
                        }
                    }
                }
            }

            boolean check = true;

            for(int i = 0; i<n; i++){
                for(int j =0; j<n; j++){
                    if(inp[i][j]=='G'){
                        check = BFS(inp,i,j,n,m);
                    }
                }
            }

            if(check){
                pw.println("Yes");
            }else{
                pw.println("No");
            }

        }
        pw.flush();

    }

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

        public int readByte(){
            if(lenbuf == -1)throw new InputMismatchException();
            if(ptrbuf >= lenbuf){
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if(lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        }
        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }
        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }
        public String next(){
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while(!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public String nextLine(){
            int b = readByte();
            StringBuilder sb = new StringBuilder();
            while(b != '\n' || b != '\r'){
                sb.appendCodePoint(b);
            }
            return sb.toString();
        }
        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
        public char[] next(int n){
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }
        public char nextChar () {
            return (char) skip();
        }
    }
}


import sun.rmi.runtime.Log;

import java.io. *;
import java.util.*;
import static java.lang.Math.*;
public class Main {

    static final FastReader sc = new FastReader(System.in);
    static final PrintWriter pw = new PrintWriter(System.out);

    static int visited[];
    static ArrayList<ArrayList<Integer>> adjlist;
    static class edge implements  Comparator<edge>{
        int dest;
        int cost;

        public edge(int dest, int cost) {
            this.dest = dest;
            this.cost = cost;
        }

        @Override
        public int compare(edge o1, edge o2) {
            return o1.cost-o2.cost;
        }
    }

    static int dist[];
    static int nodesinSubtree[];
    static int color[];
    static ArrayList<Integer> res1;
    static ArrayList<Integer> res2;

    static class Graph{
        int V;
        ArrayList<ArrayList<edge>> adj;
        PriorityQueue<edge> pq;

        public Graph(int V){
            this.V = V;
            adj = new ArrayList<>(V);
            pq = new PriorityQueue<>(V,new edge(-1,-1));
            dist = new int[V];
            nodesinSubtree = new int[V];
            color = new int[V];
            Arrays.fill(color,-1);
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
                adj.add(i,new ArrayList<>());
            }
        }

        void addedge(int u, int v, int w ){
            adj.get(u).add(new edge(v,w));
            //adj.get(v).add(new edge(u,w));
        }

        void rDfs(int src, int e){
            //nodes in a subtree
            nodesinSubtree[src] = 1;
            for(int i=0; i<adj.get(src).size(); i++){
                if(adj.get(src).get(i).dest==e){
                    continue;
                }
                rDfs(adj.get(src).get(i).dest,src);
                nodesinSubtree[src]+=nodesinSubtree[adj.get(src).get(i).dest];
            }
        }

        void uBFS(int src){
            Queue<edge> q = new LinkedList<>();
            color = new int[V];
            q.add(new edge(src,0));
            color[src] = 0;
            while (!q.isEmpty()){
                int u = q.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    if(color[adj.get(u).get(i).dest]==color[u]){
                        color[adj.get(u).get(i).dest] = color[u]+1;
                        q.add(new edge(adj.get(u).get(i).dest,0));
                    }
                }
            }
        }

        int DFS(int src){
            Stack<edge> st = new Stack<>();
            boolean visited[] = new boolean[V];
            visited[src] = true;
            st.push(new edge(src,0));
            dist[src] = 0;
            color[src] = 1;
            while (!st.empty()){
                int u = st.peek().dest;
                st.pop();
                for(int i=0; i<adj.get(u).size(); i++){
                    if(color[adj.get(u).get(i).dest]==0) {
                        if (color[u] == 0) {
                            color[adj.get(u).get(i).dest] = 1;
                        } else {
                            color[adj.get(u).get(i).dest] = 0;
                        }
                        st.push(new edge(adj.get(u).get(i).dest,0));
                    }else{
                        if(color[u]==0 && color[adj.get(u).get(i).dest]==0){
                            return -1;
                        }
                        if(color[u]==1 && color[adj.get(u).get(i).dest]==1){
                            return -1;
                        }
                    }
                }
            }
            return 0;
        }
    }

/*
        void dijkstra(int src){
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
            }
            dist[src] = 0;
            pq.add(new edge(src,0));
            while (!pq.isEmpty()){
                int u = pq.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                }
            }

        }

    }

 */

    static  int I[];
    static  int  L[];
    static void LIS(int n, int arr[]){
        I = new int[n+1];
        L = new int[n];
        I[0] = Integer.MIN_VALUE;
        for(int i=1;i<=n; i++){
            I[i] = Integer.MAX_VALUE;
        }
        int lisLength = 1;

        for(int i=n-1; i>=0; i--) {
            int low = 1;
            int high = lisLength;
            int mid = 0;
            while (low < high) {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            }
            I[high] = arr[i];
            L[i] = high;
            if(lisLength<=high){
                lisLength++;
            }
        }
    }

    public static long gcd(long a, long b)
    {
        if (a == 0)
            return b;

        return gcd(b%a, a);
    }

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

    static long nCr(long n, long r)
    {
        return fact(n) / (fact(r) * fact(n - r));
    }

    // Returns factorial of n
    static long fact(long n)
    {
        long res = 1;
        for (int i = 2; i <= n; i++)
            res = (res * i)%MOD;
        return res;
    }

    static int MOD = 1000000007;
    static int power(int x, int y, int p)
    {

        // Initialize result
        int res = 1;

        // Update x if it is more than or
        // equal to p
        x = x % p;

        while (y > 0)
        {

            // If y is odd, multiply x
            // with result
            if (y % 2 == 1)
                res = (res * x) % p;

            // y must be even now
            y = y >> 1; // y = y/2
            x = (x * x) % p;
        }

        return res;
    }

    // Returns n^(-1) mod p
    static int modInverse(int n, int p)
    {
        return power(n, p-2, p);
    }

    static int nCrModPFermat(int n, int r,
                             int p)
    {

        if (r == 0)
            return 1;

        int[] fac = new int[n+1];
        fac[0] = 1;

        for (int i = 1 ;i <= n; i++)
            fac[i] = fac[i-1] * i % p;

        return (fac[n]* modInverse(fac[r], p)
                % p * modInverse(fac[n-r], p)
                % p) % p;
    }

    static int[] phi;

    static void generatePhi(int n){
        phi = new int[n+1];

        for(int i = 0; i<=n; i++){
            phi[i] = i;
        }

        for(int i=2; i<=n; i++){
            if(phi[i]==i){
                for(int j= i; j<=n; j+=i){
                    phi[j] -= (phi[j]/i);
                }
            }
        }
    }

    static int gcdCount(int n, int d){
        return phi[n/d];
    }

    static boolean prime[];

    static void sieveOfEratosthenes(int n)
    {
        prime = new boolean[n+1];
        for(int i=0;i<n;i++)
            prime[i] = true;

        for(int p = 2; p*p <=n; p++)
        {
            if(prime[p] == true)
            {
                for(int i = p*p; i <= n; i += p)
                    prime[i] = false;
            }
        }

    }

    static double Logx(double n, int x){
        return log(n)/log(x);
    }

    static boolean isPrime(long n){
        if(n<2){
            return false;
        }
        for(int i = 2; i*i<=n; i++){
            if(n%i==0){
                return false;
            }
        }
        return true;
    }

    static boolean BFS(char inp[][], int srcx, int srcy, int n, int m){

        Queue<Integer> qx = new LinkedList<>();
        Queue<Integer> qy = new LinkedList<>();
        qx.add(srcx);
        qy.add(srcy);
        boolean visited[][] = new boolean[n][m];
        while (!qx.isEmpty() && !qy.isEmpty()){
            int u = qx.poll();
            int v = qy.poll();

            for(int i = 0; i<4; i++){
                int x = u + dx[i];
                int y = v + dy[i];
                if (x > n - 1 || x < 0 || y > m - 1 || y < 0) {
                    continue;
                }
                if(inp[x][y]!='#' && !visited[x][y]){
                    visited[x][y] = true;
                    qx.add(x);
                    qy.add(y);
                }
            }
        }
        return visited[n-1][m-1];
    }
    static int dx[] = {-1,1,0,0};
    static int dy[] = {0,0,1,-1};
    public static void main(String[] args) {

        int testcase = sc.nextInt();

        while (testcase-->0) {

            int n = sc.nextInt();
            int m = sc.nextInt();

            char inp[][] = new char[n][m];

            for(int i = 0; i<n; i++){
                for(int j =0; j<m; j++){
                    inp[i][j] = sc.nextChar();
                }
            }

            for(int i = 0; i<n; i++){
                for(int j =0; j<m; j++){
                    if(inp[i][j]=='B') {
                        for (int k = 0; k < 4; k++) {
                            int x = i + dx[k];
                            int y = j + dy[k];
                            if (x > n - 1 || x < 0 || y > m - 1 || y < 0) {
                                continue;
                            }
                            if(inp[x][y]=='.'){
                                inp[x][y] = '#';
                            }
                        }
                    }
                }
            }

            boolean check = true;

            for(int i = 0; i<n; i++){
                for(int j =0; j<m; j++){
                    if(inp[i][j]=='G'){
                        check = BFS(inp,i,j,n,m);
                    }
                }
            }

            if(check){
                pw.println("Yes");
            }else{
                pw.println("No");
            }

        }
        pw.flush();

    }

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

        public int readByte(){
            if(lenbuf == -1)throw new InputMismatchException();
            if(ptrbuf >= lenbuf){
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if(lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        }
        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }
        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }
        public String next(){
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while(!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public String nextLine(){
            int b = readByte();
            StringBuilder sb = new StringBuilder();
            while(b != '\n' || b != '\r'){
                sb.appendCodePoint(b);
            }
            return sb.toString();
        }
        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
        public char[] next(int n){
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }
        public char nextChar () {
            return (char) skip();
        }
    }
}


import sun.rmi.runtime.Log;

import java.io. *;
import java.util.*;
import static java.lang.Math.*;
public class Main {

    static final FastReader sc = new FastReader(System.in);
    static final PrintWriter pw = new PrintWriter(System.out);

    static int visited[];
    static ArrayList<ArrayList<Integer>> adjlist;
    static class edge implements  Comparator<edge>{
        int dest;
        int cost;

        public edge(int dest, int cost) {
            this.dest = dest;
            this.cost = cost;
        }

        @Override
        public int compare(edge o1, edge o2) {
            return o1.cost-o2.cost;
        }
    }

    static int dist[];
    static int nodesinSubtree[];
    static int color[];
    static ArrayList<Integer> res1;
    static ArrayList<Integer> res2;

    static class Graph{
        int V;
        ArrayList<ArrayList<edge>> adj;
        PriorityQueue<edge> pq;

        public Graph(int V){
            this.V = V;
            adj = new ArrayList<>(V);
            pq = new PriorityQueue<>(V,new edge(-1,-1));
            dist = new int[V];
            nodesinSubtree = new int[V];
            color = new int[V];
            Arrays.fill(color,-1);
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
                adj.add(i,new ArrayList<>());
            }
        }

        void addedge(int u, int v, int w ){
            adj.get(u).add(new edge(v,w));
            //adj.get(v).add(new edge(u,w));
        }

        void rDfs(int src, int e){
            //nodes in a subtree
            nodesinSubtree[src] = 1;
            for(int i=0; i<adj.get(src).size(); i++){
                if(adj.get(src).get(i).dest==e){
                    continue;
                }
                rDfs(adj.get(src).get(i).dest,src);
                nodesinSubtree[src]+=nodesinSubtree[adj.get(src).get(i).dest];
            }
        }

        void uBFS(int src){
            Queue<edge> q = new LinkedList<>();
            color = new int[V];
            q.add(new edge(src,0));
            color[src] = 0;
            while (!q.isEmpty()){
                int u = q.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    if(color[adj.get(u).get(i).dest]==color[u]){
                        color[adj.get(u).get(i).dest] = color[u]+1;
                        q.add(new edge(adj.get(u).get(i).dest,0));
                    }
                }
            }
        }

        int DFS(int src){
            Stack<edge> st = new Stack<>();
            boolean visited[] = new boolean[V];
            visited[src] = true;
            st.push(new edge(src,0));
            dist[src] = 0;
            color[src] = 1;
            while (!st.empty()){
                int u = st.peek().dest;
                st.pop();
                for(int i=0; i<adj.get(u).size(); i++){
                    if(color[adj.get(u).get(i).dest]==0) {
                        if (color[u] == 0) {
                            color[adj.get(u).get(i).dest] = 1;
                        } else {
                            color[adj.get(u).get(i).dest] = 0;
                        }
                        st.push(new edge(adj.get(u).get(i).dest,0));
                    }else{
                        if(color[u]==0 && color[adj.get(u).get(i).dest]==0){
                            return -1;
                        }
                        if(color[u]==1 && color[adj.get(u).get(i).dest]==1){
                            return -1;
                        }
                    }
                }
            }
            return 0;
        }
    }

/*
        void dijkstra(int src){
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
            }
            dist[src] = 0;
            pq.add(new edge(src,0));
            while (!pq.isEmpty()){
                int u = pq.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                }
            }

        }

    }

 */

    static  int I[];
    static  int  L[];
    static void LIS(int n, int arr[]){
        I = new int[n+1];
        L = new int[n];
        I[0] = Integer.MIN_VALUE;
        for(int i=1;i<=n; i++){
            I[i] = Integer.MAX_VALUE;
        }
        int lisLength = 1;

        for(int i=n-1; i>=0; i--) {
            int low = 1;
            int high = lisLength;
            int mid = 0;
            while (low < high) {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            }
            I[high] = arr[i];
            L[i] = high;
            if(lisLength<=high){
                lisLength++;
            }
        }
    }

    public static long gcd(long a, long b)
    {
        if (a == 0)
            return b;

        return gcd(b%a, a);
    }

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

    static long nCr(long n, long r)
    {
        return fact(n) / (fact(r) * fact(n - r));
    }

    // Returns factorial of n
    static long fact(long n)
    {
        long res = 1;
        for (int i = 2; i <= n; i++)
            res = (res * i)%MOD;
        return res;
    }

    static int MOD = 1000000007;
    static int power(int x, int y, int p)
    {

        // Initialize result
        int res = 1;

        // Update x if it is more than or
        // equal to p
        x = x % p;

        while (y > 0)
        {

            // If y is odd, multiply x
            // with result
            if (y % 2 == 1)
                res = (res * x) % p;

            // y must be even now
            y = y >> 1; // y = y/2
            x = (x * x) % p;
        }

        return res;
    }

    // Returns n^(-1) mod p
    static int modInverse(int n, int p)
    {
        return power(n, p-2, p);
    }

    static int nCrModPFermat(int n, int r,
                             int p)
    {

        if (r == 0)
            return 1;

        int[] fac = new int[n+1];
        fac[0] = 1;

        for (int i = 1 ;i <= n; i++)
            fac[i] = fac[i-1] * i % p;

        return (fac[n]* modInverse(fac[r], p)
                % p * modInverse(fac[n-r], p)
                % p) % p;
    }

    static int[] phi;

    static void generatePhi(int n){
        phi = new int[n+1];

        for(int i = 0; i<=n; i++){
            phi[i] = i;
        }

        for(int i=2; i<=n; i++){
            if(phi[i]==i){
                for(int j= i; j<=n; j+=i){
                    phi[j] -= (phi[j]/i);
                }
            }
        }
    }

    static int gcdCount(int n, int d){
        return phi[n/d];
    }

    static boolean prime[];

    static void sieveOfEratosthenes(int n)
    {
        prime = new boolean[n+1];
        for(int i=0;i<n;i++)
            prime[i] = true;

        for(int p = 2; p*p <=n; p++)
        {
            if(prime[p] == true)
            {
                for(int i = p*p; i <= n; i += p)
                    prime[i] = false;
            }
        }

    }

    static double Logx(double n, int x){
        return log(n)/log(x);
    }

    static boolean isPrime(long n){
        if(n<2){
            return false;
        }
        for(int i = 2; i*i<=n; i++){
            if(n%i==0){
                return false;
            }
        }
        return true;
    }

    static boolean BFS(char inp[][], int srcx, int srcy, int n, int m){

        if(totalGoodGuys==0 && inp[n-1][m-1]=='#'){
            return true;
        }
        Queue<Integer> qx = new LinkedList<>();
        Queue<Integer> qy = new LinkedList<>();
        qx.add(srcx);
        qy.add(srcy);
        boolean visited[][] = new boolean[n][m];
        int goodGuys = 0;
        int badGuys = 0;
        while (!qx.isEmpty() && !qy.isEmpty()){
            int u = qx.poll();
            int v = qy.poll();

            if(inp[u][v]=='G'){
                goodGuys++;
            }

            if(inp[u][v]=='B'){
                badGuys++;
            }

            for(int i = 0; i<4; i++){
                int x = u + dx[i];
                int y = v + dy[i];
                if (x > n - 1 || x < 0 || y > m - 1 || y < 0) {
                    continue;
                }
                if(inp[x][y]!='#' && !visited[x][y]){
                    visited[x][y] = true;
                    qx.add(x);
                    qy.add(y);
                }
            }
        }
        return goodGuys==totalGoodGuys && badGuys==0;
    }
    static int dx[] = {-1,1,0,0};
    static int dy[] = {0,0,1,-1};
    static int totalGoodGuys = 0;
    public static void main(String[] args) {

        int testcase = sc.nextInt();

        while (testcase-->0) {

            int n = sc.nextInt();
            int m = sc.nextInt();

            char inp[][] = new char[n][m];

            totalGoodGuys = 0;

            for(int i = 0; i<n; i++){
                for(int j =0; j<m; j++){
                    inp[i][j] = sc.nextChar();
                }
            }

            for(int i = 0; i<n; i++){
                for(int j =0; j<m; j++){
                    if(inp[i][j]=='B') {
                        for (int k = 0; k < 4; k++) {
                            int x = i + dx[k];
                            int y = j + dy[k];
                            if (x > n - 1 || x < 0 || y > m - 1 || y < 0) {
                                continue;
                            }
                            if(inp[x][y]=='.'){
                                inp[x][y] = '#';
                            }
                        }
                    }else if(inp[i][j]=='G'){
                        totalGoodGuys++;
                    }
                }
            }

            if(BFS(inp,n-1,m-1,n,m)){
                pw.println("Yes");
            }else{
                pw.println("No");
            }

        }
        pw.flush();

    }

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

        public int readByte(){
            if(lenbuf == -1)throw new InputMismatchException();
            if(ptrbuf >= lenbuf){
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if(lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        }
        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }
        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }
        public String next(){
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while(!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public String nextLine(){
            int b = readByte();
            StringBuilder sb = new StringBuilder();
            while(b != '\n' || b != '\r'){
                sb.appendCodePoint(b);
            }
            return sb.toString();
        }
        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
        public char[] next(int n){
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }
        public char nextChar () {
            return (char) skip();
        }
    }
}


import sun.rmi.runtime.Log;

import java.io. *;
import java.util.*;
import static java.lang.Math.*;
public class Main {

    static final FastReader sc = new FastReader(System.in);
    static final PrintWriter pw = new PrintWriter(System.out);

    static int visited[];
    static ArrayList<ArrayList<Integer>> adjlist;
    static class edge implements  Comparator<edge>{
        int dest;
        int cost;

        public edge(int dest, int cost) {
            this.dest = dest;
            this.cost = cost;
        }

        @Override
        public int compare(edge o1, edge o2) {
            return o1.cost-o2.cost;
        }
    }

    static int dist[];
    static int nodesinSubtree[];
    static int color[];
    static ArrayList<Integer> res1;
    static ArrayList<Integer> res2;

    static class Graph{
        int V;
        ArrayList<ArrayList<edge>> adj;
        PriorityQueue<edge> pq;

        public Graph(int V){
            this.V = V;
            adj = new ArrayList<>(V);
            pq = new PriorityQueue<>(V,new edge(-1,-1));
            dist = new int[V];
            nodesinSubtree = new int[V];
            color = new int[V];
            Arrays.fill(color,-1);
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
                adj.add(i,new ArrayList<>());
            }
        }

        void addedge(int u, int v, int w ){
            adj.get(u).add(new edge(v,w));
            //adj.get(v).add(new edge(u,w));
        }

        void rDfs(int src, int e){
            //nodes in a subtree
            nodesinSubtree[src] = 1;
            for(int i=0; i<adj.get(src).size(); i++){
                if(adj.get(src).get(i).dest==e){
                    continue;
                }
                rDfs(adj.get(src).get(i).dest,src);
                nodesinSubtree[src]+=nodesinSubtree[adj.get(src).get(i).dest];
            }
        }

        void uBFS(int src){
            Queue<edge> q = new LinkedList<>();
            color = new int[V];
            q.add(new edge(src,0));
            color[src] = 0;
            while (!q.isEmpty()){
                int u = q.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    if(color[adj.get(u).get(i).dest]==color[u]){
                        color[adj.get(u).get(i).dest] = color[u]+1;
                        q.add(new edge(adj.get(u).get(i).dest,0));
                    }
                }
            }
        }

        int DFS(int src){
            Stack<edge> st = new Stack<>();
            boolean visited[] = new boolean[V];
            visited[src] = true;
            st.push(new edge(src,0));
            dist[src] = 0;
            color[src] = 1;
            while (!st.empty()){
                int u = st.peek().dest;
                st.pop();
                for(int i=0; i<adj.get(u).size(); i++){
                    if(color[adj.get(u).get(i).dest]==0) {
                        if (color[u] == 0) {
                            color[adj.get(u).get(i).dest] = 1;
                        } else {
                            color[adj.get(u).get(i).dest] = 0;
                        }
                        st.push(new edge(adj.get(u).get(i).dest,0));
                    }else{
                        if(color[u]==0 && color[adj.get(u).get(i).dest]==0){
                            return -1;
                        }
                        if(color[u]==1 && color[adj.get(u).get(i).dest]==1){
                            return -1;
                        }
                    }
                }
            }
            return 0;
        }
    }

/*
        void dijkstra(int src){
            for(int i=0; i<V; i++){
                dist[i] = Integer.MAX_VALUE;
            }
            dist[src] = 0;
            pq.add(new edge(src,0));
            while (!pq.isEmpty()){
                int u = pq.poll().dest;
                for(int i=0; i<adj.get(u).size(); i++){
                    int v = adj.get(u).get(i).dest;
                    int w = adj.get(u).get(i).cost;
                    if(dist[u]+w<=dist[v]){
                        dist[v] = dist[u] + w;
                        pq.add(new edge(v,dist[v]));
                    }
                }
            }

        }

    }

 */

    static  int I[];
    static  int  L[];
    static void LIS(int n, int arr[]){
        I = new int[n+1];
        L = new int[n];
        I[0] = Integer.MIN_VALUE;
        for(int i=1;i<=n; i++){
            I[i] = Integer.MAX_VALUE;
        }
        int lisLength = 1;

        for(int i=n-1; i>=0; i--) {
            int low = 1;
            int high = lisLength;
            int mid = 0;
            while (low < high) {
                mid = (low + high) >> 1;
                if (I[mid] <= arr[i]) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            }
            I[high] = arr[i];
            L[i] = high;
            if(lisLength<=high){
                lisLength++;
            }
        }
    }

    public static long gcd(long a, long b)
    {
        if (a == 0)
            return b;

        return gcd(b%a, a);
    }

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

    static long nCr(long n, long r)
    {
        return fact(n) / (fact(r) * fact(n - r));
    }

    // Returns factorial of n
    static long fact(long n)
    {
        long res = 1;
        for (int i = 2; i <= n; i++)
            res = (res * i)%MOD;
        return res;
    }

    static int MOD = 1000000007;
    static int power(int x, int y, int p)
    {

        // Initialize result
        int res = 1;

        // Update x if it is more than or
        // equal to p
        x = x % p;

        while (y > 0)
        {

            // If y is odd, multiply x
            // with result
            if (y % 2 == 1)
                res = (res * x) % p;

            // y must be even now
            y = y >> 1; // y = y/2
            x = (x * x) % p;
        }

        return res;
    }

    // Returns n^(-1) mod p
    static int modInverse(int n, int p)
    {
        return power(n, p-2, p);
    }

    static int nCrModPFermat(int n, int r,
                             int p)
    {

        if (r == 0)
            return 1;

        int[] fac = new int[n+1];
        fac[0] = 1;

        for (int i = 1 ;i <= n; i++)
            fac[i] = fac[i-1] * i % p;

        return (fac[n]* modInverse(fac[r], p)
                % p * modInverse(fac[n-r], p)
                % p) % p;
    }

    static int[] phi;

    static void generatePhi(int n){
        phi = new int[n+1];

        for(int i = 0; i<=n; i++){
            phi[i] = i;
        }

        for(int i=2; i<=n; i++){
            if(phi[i]==i){
                for(int j= i; j<=n; j+=i){
                    phi[j] -= (phi[j]/i);
                }
            }
        }
    }

    static int gcdCount(int n, int d){
        return phi[n/d];
    }

    static boolean prime[];

    static void sieveOfEratosthenes(int n)
    {
        prime = new boolean[n+1];
        for(int i=0;i<n;i++)
            prime[i] = true;

        for(int p = 2; p*p <=n; p++)
        {
            if(prime[p] == true)
            {
                for(int i = p*p; i <= n; i += p)
                    prime[i] = false;
            }
        }

    }

    static double Logx(double n, int x){
        return log(n)/log(x);
    }

    static boolean isPrime(long n){
        if(n<2){
            return false;
        }
        for(int i = 2; i*i<=n; i++){
            if(n%i==0){
                return false;
            }
        }
        return true;
    }

    static boolean BFS(char inp[][], int srcx, int srcy, int n, int m){

        Queue<Integer> qx = new LinkedList<>();
        Queue<Integer> qy = new LinkedList<>();
        qx.add(srcx);
        qy.add(srcy);
        boolean visited[][] = new boolean[n][m];
        while (!qx.isEmpty() && !qy.isEmpty()){
            int u = qx.poll();
            int v = qy.poll();

            for(int i = 0; i<4; i++){
                int x = u + dx[i];
                int y = v + dy[i];
                if (x > n - 1 || x < 0 || y > m - 1 || y < 0) {
                    continue;
                }
                if(inp[x][y]!='#' && !visited[x][y]){
                    visited[x][y] = true;
                    qx.add(x);
                    qy.add(y);
                }
            }
        }
        return visited[n-1][m-1];
    }
    static int dx[] = {-1,1,0,0};
    static int dy[] = {0,0,1,-1};
    public static void main(String[] args) {

        int testcase = sc.nextInt();

        while (testcase-->0) {

            int n = sc.nextInt();
            int m = sc.nextInt();

            char inp[][] = new char[n][m];

            for(int i = 0; i<n; i++){
                for(int j =0; j<m; j++){
                    inp[i][j] = sc.nextChar();
                }
            }

            for(int i = 0; i<n; i++){
                for(int j =0; j<m; j++){
                    if(inp[i][j]=='B') {
                        for (int k = 0; k < 4; k++) {
                            int x = i + dx[k];
                            int y = j + dy[k];
                            if (x > n - 1 || x < 0 || y > m - 1 || y < 0) {
                                continue;
                            }
                            if(inp[x][y]=='.'){
                                inp[x][y] = '#';
                            }
                        }
                    }
                }
            }

            boolean checkgg = true;
            boolean checkbg = false;

            for(int i = 0; i<n; i++){
                for(int j =0; j<m; j++){
                    if(inp[i][j]=='G'){
                        checkgg = BFS(inp,i,j,n,m);
                    }else if(inp[i][j]=='B'){
                        checkbg = BFS(inp,i,j,n,m);
                    }
                }
            }

            if(!checkbg && checkgg){
                pw.println("Yes");
            }else{
                pw.println("No");
            }

        }
        pw.flush();

    }

    static void debug(Object...obj) {
        System.err.println(Arrays.deepToString(obj));
    }

    static class FastReader {
        InputStream is;
        private byte[] inbuf = new byte[1024];
        private int lenbuf = 0, ptrbuf = 0;

        public FastReader(InputStream is) {
            this.is = is;
        }

        public int readByte(){
            if(lenbuf == -1)throw new InputMismatchException();
            if(ptrbuf >= lenbuf){
                ptrbuf = 0;
                try {
                    lenbuf = is.read(inbuf);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }
                if(lenbuf <= 0)
                    return -1;
            }
            return inbuf[ptrbuf++];
        }
        public boolean isSpaceChar(int c) {
            return !(c >= 33 && c <= 126);
        }
        public int skip() {
            int b;
            while ((b = readByte()) != -1 && isSpaceChar(b)) ;
            return b;
        }
        public String next(){
            int b = skip();
            StringBuilder sb = new StringBuilder();
            while(!(isSpaceChar(b))) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public String nextLine(){
            int b = readByte();
            StringBuilder sb = new StringBuilder();
            while(b != '\n' || b != '\r'){
                sb.appendCodePoint(b);
            }
            return sb.toString();
        }
        public int nextInt() {
            int num = 0, b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public long nextLong() {
            long num = 0;
            int b;
            boolean minus = false;
            while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            while (true) {
                if (b >= '0' && b <= '9') {
                    num = (num << 3) + (num << 1) + (b - '0');
                } else {
                    return minus ? -num : num;
                }
                b = readByte();
            }
        }
        public double nextDouble() {
            return Double.parseDouble(next());
        }
        public char[] next(int n){
            char[] buf = new char[n];
            int b = skip(), p = 0;
            while (p < n && !(isSpaceChar(b))) {
                buf[p++] = (char) b;
                b = readByte();
            }
            return n == p ? buf : Arrays.copyOf(buf, p);
        }
        public char nextChar () {
            return (char) skip();
        }
    }
}


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

public class D2 { // TLE case 10

    static int[] dr = {1, 0, -1, 0};
    static int[] dc = {0, 1, 0, -1};
    static int[][] grid = new int[52][52]; //0: grid; 1: close; 2: end

    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
            int testCnt = Integer.parseInt(br.readLine());
            Arrays.fill(grid[0], 1);
            for (int i = 0; i < testCnt; i++) {
                String[] line = br.readLine().split(" ");
                int rowCnt = Integer.parseInt(line[0]);
                int colCnt = Integer.parseInt(line[1]);
                //create boundaries:
                for (int j = 1; j <= rowCnt; j++) {
                    Arrays.fill(grid[j], 0);
                    grid[j][0] = 1;
                    grid[j][colCnt + 1] = 1;
                }
                Arrays.fill(grid[rowCnt + 1], 1);
                //scan in:
                int gCnt = 0;
                for (int j = 0; j < rowCnt; j++) {
                    String curRow = br.readLine();
                    for (int k = 0; k < colCnt; k++) {
                        char cur = curRow.charAt(k);
                        if (cur == '#') grid[j + 1][k + 1] = 1;
                        else if (cur == 'G') {
                            grid[j + 1][k + 1] = 2;
                            gCnt++;
                        }
                        else if (cur == 'B') {
                            dbug("<>. <> <> ", i, j, k);
                            for (int l = 0; l < 4; l++) {
                                dbug("<>. <> <> ", l, j + 1 + dr[l], k + 1 + dc[l]);
                                grid[j + 1 + dr[l]][k + 1 + dc[l]] = 1;
                            }
                        }
                    }
                }

                if (gCnt == 0) {
                    bw.write("Yes\n");
                    continue;
                }
                if (grid[rowCnt][colCnt] == 1) {
                    bw.write("No\n");
                    continue;
                }

                print(grid, rowCnt, colCnt);

                int endCnt = 0;
                int[][] q = new int[rowCnt * colCnt][2];
                boolean[][] visited = new boolean[rowCnt + 2][colCnt + 2];
                q[0][0] = rowCnt;
                q[0][1] = colCnt;
                int write = 1;
                visited[rowCnt][colCnt] = true;
                for (int read = 0; read < write; read++) {
                    int curRow = q[read][0];
                    int curCol = q[read][1];
                    dbug("<>) <> <> at <> <> ", read, q[read][0], q[read][1], curRow, curCol);

                    if (grid[curRow][curCol] == 2) endCnt++;

                    for (int j = 0; j < 4; j++) {
                        int newRow = curRow + dr[j];
                        int newCol = curCol + dc[j];
                        if (!visited[newRow][newCol] && grid[newRow][newCol] != 1) {
                            dbug("<>. <> <> <> ", j, write, newRow, newCol);
                            visited[newRow][newCol] = true;
                            q[write][0] = newRow;
                            q[write][1] = newCol;
                            write++;
                        }
                    }
                }

                if (i == 1) print(q, 0, 0);

                bw.write((endCnt == gCnt)? "Yes\n": "No\n");

                dbug("");
            }
            br.close();
            bw.close();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void dbug(String s, long ... a) { /*
        String[] line = s.split("<>");
        for (int i = 0; i < a.length; i++) {
            System.out.print(line[i] + a[i]);
        }
        System.out.println(line[a.length]); // */
    }

    public static void print(int[][] a, int rowCnt, int colCnt) { /*
        for (int i = 0; i <= rowCnt + 1; i++) {
            for (int j = 0; j <= colCnt + 1; j++) {
                System.out.print(a[i][j] + " ");
            }
            System.out.println();
        }
        System.out.println(); // */
    }
}


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

public class D { //

    static int[] dr = {1, 0, -1, 0};
    static int[] dc = {0, 1, 0, -1};
    static int[][] s = new int[2500][2];
    static boolean[][] open = new boolean[52][52];

    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
            int testCnt = Integer.parseInt(br.readLine());
            for (int i = 0; i < testCnt; i++) {
                String[] line = br.readLine().split(" ");
                int rowCnt = Integer.parseInt(line[0]);
                int colCnt = Integer.parseInt(line[1]);
                //create boundaries:
                for (int j = 1; j <= rowCnt; j++) {
                    Arrays.fill(open[j], true);
                    open[j][0] = false;
                    open[j][colCnt + 1] = false;
                }
                Arrays.fill(open[rowCnt + 1], false);
                //scan in:
                int write = 0;
                for (int j = 0; j < rowCnt; j++) {
                    String curRow = br.readLine();
                    for (int k = 0; k < colCnt; k++) {
                        char cur = curRow.charAt(k);
                        if (cur == '#') open[j + 1][k + 1] = false;
                        else if (cur == 'G') {
                            s[write][0] = j + 1;
                            s[write][1] = k + 1;
                            write++;
                        }
                        else if (cur == 'B') {
                            dbug("<>. <> <> ", i, j, k);
                            for (int l = 0; l < 4; l++) {
                                dbug("<>. <> <> ", l, j + 1 + dr[l], k + 1 + dc[l]);
                                open[j + 1 + dr[l]][k + 1 + dc[l]] = false;
                            }
                        }
                    }
                }
                print(open, rowCnt, colCnt);

                boolean works = true;
                for (int j = 0; j < write; j++) {
                    if (!bfs(j, rowCnt, colCnt)) {
                        works = false;
                        break;
                    }
                }

                bw.write((works)? "Yes\n": "No\n");
            }
            br.close();
            bw.close();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static boolean bfs(int idx, int r, int c) {
        if (!open[s[idx][0]][s[idx][1]]) return false;
        boolean[][] visited = new boolean[r + 2][c + 2];
        int[][] q = new int[r * c][2];
        q[0][0] = s[idx][0];
        q[0][1] = s[idx][1];
        visited[q[0][0]][q[0][1]] = true;
        int write = 1;
        for (int read = 0; read < write; read++) {
            int curRow = q[read][0];
            int curCol = q[read][1];

            if (curRow == r && curCol == c) return true;

            for (int i = 0; i < 4; i++) {
                int newRow = curRow + dr[i];
                int newCol = curCol + dc[i];
                if (!visited[newRow][newCol] && open[newRow][newCol]) {
                    visited[newRow][newCol] = true;
                    q[write][0] = newRow;
                    q[write][1] = newCol;
                    write++;
                }
            }
        }
        return false;
    }

    public static void dbug(String s, long ... a) { /*
        String[] line = s.split("<>");
        for (int i = 0; i < a.length; i++) {
            System.out.print(line[i] + a[i]);
        }
        System.out.println(line[a.length]); // */
    }

    public static void print(boolean[][] a, int rowCnt, int colCnt) { /*
        for (int i = 0; i <= rowCnt + 1; i++) {
            for (int j = 0; j <= colCnt + 1; j++) {
                System.out.print((a[i][j])? ".": "#");
            }
            System.out.println();
        }
        System.out.println(); // */
    }
}


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

public class D2 { // TLE case 10

    static int[] dr = {1, 0, -1, 0};
    static int[] dc = {0, 1, 0, -1};
    static int[][] grid = new int[52][52]; //0: grid; 1: close; 2: end

    public static void main(String[] args) {
        try {
            BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
            BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
            int testCnt = Integer.parseInt(br.readLine());
            Arrays.fill(grid[0], 1);
            for (int i = 0; i < testCnt; i++) {
                String[] line = br.readLine().split(" ");
                int rowCnt = Integer.parseInt(line[0]);
                int colCnt = Integer.parseInt(line[1]);
                //create boundaries:
                for (int j = 1; j <= rowCnt; j++) {
                    Arrays.fill(grid[j], 0);
                    grid[j][0] = 1;
                    grid[j][colCnt + 1] = 1;
                }
                Arrays.fill(grid[rowCnt + 1], 1);
                //scan in:
                int gCnt = 0;
                for (int j = 0; j < rowCnt; j++) {
                    String curRow = br.readLine();
                    for (int k = 0; k < colCnt; k++) {
                        char cur = curRow.charAt(k);
                        if (cur == '#') grid[j + 1][k + 1] = 1;
                        else if (cur == 'G') {
                            if (grid[j + 1][k + 1] == 0) grid[j + 1][k + 1] = 2;
                            gCnt++;
                        }
                        else if (cur == 'B') {
                            dbug("<>. <> <> ", i, j, k);
                            for (int l = 0; l < 4; l++) {
                                dbug("<>. <> <> ", l, j + 1 + dr[l], k + 1 + dc[l]);
                                grid[j + 1 + dr[l]][k + 1 + dc[l]] = 1;
                            }
                        }
                    }
                }

                if (gCnt == 0) {
                    bw.write("Yes\n");
                    continue;
                }
                if (grid[rowCnt][colCnt] == 1) {
                    bw.write("No\n");
                    continue;
                }

                print(grid, rowCnt, colCnt);

                int endCnt = 0;
                int[][] q = new int[rowCnt * colCnt][2];
                boolean[][] visited = new boolean[rowCnt + 2][colCnt + 2];
                q[0][0] = rowCnt;
                q[0][1] = colCnt;
                int write = 1;
                visited[rowCnt][colCnt] = true;
                for (int read = 0; read < write; read++) {
                    int curRow = q[read][0];
                    int curCol = q[read][1];
                    dbug("<>) <> <> at <> <> ", read, q[read][0], q[read][1], curRow, curCol);

                    if (grid[curRow][curCol] == 2) endCnt++;

                    for (int j = 0; j < 4; j++) {
                        int newRow = curRow + dr[j];
                        int newCol = curCol + dc[j];
                        if (!visited[newRow][newCol] && grid[newRow][newCol] != 1) {
                            dbug("<>. <> <> <> ", j, write, newRow, newCol);
                            visited[newRow][newCol] = true;
                            q[write][0] = newRow;
                            q[write][1] = newCol;
                            write++;
                        }
                    }
                }

                if (i == 1) print(q, 0, 0);

                bw.write((endCnt == gCnt)? "Yes\n": "No\n");

                dbug("");
            }
            br.close();
            bw.close();
        }
        catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void dbug(String s, long ... a) { /*
        String[] line = s.split("<>");
        for (int i = 0; i < a.length; i++) {
            System.out.print(line[i] + a[i]);
        }
        System.out.println(line[a.length]); // */
    }

    public static void print(int[][] a, int rowCnt, int colCnt) { /*
        for (int i = 0; i <= rowCnt + 1; i++) {
            for (int j = 0; j <= colCnt + 1; j++) {
                System.out.print(a[i][j] + " ");
            }
            System.out.println();
        }
        System.out.println(); // */
    }
}


/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.io.*;
import java.util.*;
public class Main
{
    private static String process(char[][] mat) {
        int n = mat.length;
        int m = mat[0].length;
        int[][] moves = new int[][]{{1,0},{-1,0},{0,1},{0,-1}};
        boolean successfullyBlocked = true;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                if (mat[i][j] == 'B') {
                    for(int[] move : moves) {
                        int dx = i+move[0];
                        int dy = j+move[1];
                        if (dx>=0 && dx < n && dy >= 0 && dy < m) {
                            if (mat[dx][dy] == '.') mat[dx][dy]='#';
                            else if (mat[dx][dy] != '#') successfullyBlocked = false;
                        }
                    }
                }
            }
        }
        int[][] cache = new int[n][m];
        for(int i = 0; i < n; i++) Arrays.fill(cache[i],-1);
        boolean ans = true;
        boolean[][] visited = new boolean[n][m];
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                if (mat[i][j] == 'G') {
                    ans = ans && isPossible(i,j,cache,mat,moves,new boolean[n][m]);
                }
            }
        }

        return ans&&successfullyBlocked ? "Yes" : "No";
    }
    private static boolean isPossible(int x, int y, int[][] cache, char[][] mat, int[][] moves, boolean[][] visited) {
        int n = mat.length;
        int m = mat[0].length;

        if (x<0 || x >= n || y < 0 || y >= m || mat[x][y] == '#') return false;
        else if (x == n-1 && y == m-1) return true;
        else if (cache[x][y] != -1) return cache[x][y]==1;
        else {
            boolean ans = false;
            visited[x][y]=true;
            for (int[] move : moves) {
                int dx = x+move[0];
                int dy = y+move[1];
                if (dx>=0 && dx < n && dy >= 0 && dy < m && !visited[dx][dy]) {
                    ans = ans || isPossible(dx,dy,cache,mat,moves,visited);
                }
            }
            cache[x][y]=ans?1:0;
            return cache[x][y]==1;
        }
    }
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine());
		while(t-- > 0) {
		    StringTokenizer tok = new StringTokenizer(br.readLine());
		    int n = Integer.parseInt(tok.nextToken());
		    int m = Integer.parseInt(tok.nextToken());
		    char[][] mat = new char[n][m];
		    for(int i = 0; i < n; i++) {
		        String line = br.readLine();
		        for(int j = 0; j < m; j++) {
		            mat[i][j] = line.charAt(j);
		        }
		    }
		    System.out.println(process(mat));
		}
	}
}


/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.io.*;
import java.util.*;
public class Main
{
    private static String process(char[][] mat) {
        int n = mat.length;
        int m = mat[0].length;
        int[][] moves = new int[][]{{1,0},{-1,0},{0,1},{0,-1}};
        boolean successfullyBlocked = true;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                if (mat[i][j] == 'B') {
                    for(int[] move : moves) {
                        int dx = i+move[0];
                        int dy = j+move[1];
                        if (dx>=0 && dx < n && dy >= 0 && dy < m) {
                            if (mat[dx][dy] == '.') mat[dx][dy]='#';
                            else if (mat[dx][dy] == 'G') successfullyBlocked = false;
                        }
                    }
                }
            }
        }
        int[][] cache = new int[n][m];
        for(int i = 0; i < n; i++) Arrays.fill(cache[i],-1);
        boolean ans = true;
        boolean[][] visited = new boolean[n][m];
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                if (mat[i][j] == 'G') {
                    ans = ans && isPossible(i,j,cache,mat,moves,new boolean[n][m]);
                }
            }
        }

        return ans&&successfullyBlocked ? "Yes" : "No";
    }
    private static boolean isPossible(int x, int y, int[][] cache, char[][] mat, int[][] moves, boolean[][] visited) {
        int n = mat.length;
        int m = mat[0].length;

        if (x<0 || x >= n || y < 0 || y >= m || mat[x][y] == '#') return false;
        else if (x == n-1 && y == m-1) return true;
        else if (cache[x][y] != -1) return cache[x][y]==1;
        else {
            boolean ans = false;
            visited[x][y]=true;
            for (int[] move : moves) {
                int dx = x+move[0];
                int dy = y+move[1];
                if (dx>=0 && dx < n && dy >= 0 && dy < m && !visited[dx][dy]) {
                    ans = ans || isPossible(dx,dy,cache,mat,moves,visited);
                }
            }
            cache[x][y]=ans?1:0;
            return cache[x][y]==1;
        }
    }
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine());
		while(t-- > 0) {
		    StringTokenizer tok = new StringTokenizer(br.readLine());
		    int n = Integer.parseInt(tok.nextToken());
		    int m = Integer.parseInt(tok.nextToken());
		    char[][] mat = new char[n][m];
		    for(int i = 0; i < n; i++) {
		        String line = br.readLine();
		        for(int j = 0; j < m; j++) {
		            mat[i][j] = line.charAt(j);
		        }
		    }
		    System.out.println(process(mat));
		}
	}
}


/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.io.*;
import java.util.*;
public class Main
{
    private static String process(char[][] mat) {
        int n = mat.length;
        int m = mat[0].length;
        int[][] moves = new int[][]{{1,0},{-1,0},{0,1},{0,-1}};
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                if (mat[i][j] == 'B') {
                    for(int[] move : moves) {
                        int dx = i+move[0];
                        int dy = j+move[1];
                        if (dx>=0 && dx < n && dy >= 0 && dy < m && mat[dx][dy] == '.') {
                            mat[dx][dy]='#';
                        }
                    }
                }
            }
        }
        int[][] cache = new int[n][m];
        for(int i = 0; i < n; i++) Arrays.fill(cache[i],-1);
        boolean ans = true;
        boolean[][] visited = new boolean[n][m];
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                if (mat[i][j] == 'G') {
                    ans = ans && isPossible(i,j,cache,mat,moves,new boolean[n][m]);
                }
            }
        }

        return ans ? "Yes" : "No";
    }
    private static boolean isPossible(int x, int y, int[][] cache, char[][] mat, int[][] moves, boolean[][] visited) {
        int n = mat.length;
        int m = mat[0].length;

        if (x<0 || x >= n || y < 0 || y >= m || mat[x][y] == '#') return false;
        else if (x == n-1 && y == m-1) return true;
        else if (cache[x][y] != -1) return cache[x][y]==1;
        else {
            boolean ans = false;
            visited[x][y]=true;
            for (int[] move : moves) {
                int dx = x+move[0];
                int dy = y+move[1];
                if (dx>=0 && dx < n && dy >= 0 && dy < m && !visited[dx][dy]) {
                    ans = ans || isPossible(dx,dy,cache,mat,moves,visited);
                }
            }
            cache[x][y]=ans?1:0;
            return cache[x][y]==1;
        }
    }
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine());
		while(t-- > 0) {
		    StringTokenizer tok = new StringTokenizer(br.readLine());
		    int n = Integer.parseInt(tok.nextToken());
		    int m = Integer.parseInt(tok.nextToken());
		    char[][] mat = new char[n][m];
		    for(int i = 0; i < n; i++) {
		        String line = br.readLine();
		        for(int j = 0; j < m; j++) {
		            mat[i][j] = line.charAt(j);
		        }
		    }
		    System.out.println(process(mat));
		}
	}
}


/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.io.*;
import java.util.*;
public class Main
{
    private static String process(char[][] mat) {
        int n = mat.length;
        int m = mat[0].length;
        int[][] moves = new int[][]{{1,0},{-1,0},{0,1},{0,-1}};
        boolean successfullyBlocked = true;
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                if (mat[i][j] == 'B') {
                    for(int[] move : moves) {
                        int dx = i+move[0];
                        int dy = j+move[1];
                        if (dx>=0 && dx < n && dy >= 0 && dy < m) {
                            if (mat[dx][dy] == '.') mat[dx][dy]='#';
                            else if (mat[dx][dy] == 'G') successfullyBlocked = false;
                        }
                    }
                }
            }
        }
        int[][] cache = new int[n][m];
        for(int i = 0; i < n; i++) Arrays.fill(cache[i],-1);
        boolean ans = true;
        boolean[][] visited = new boolean[n][m];
        for(int i = 0; i < n; i++) {
            for(int j = 0; j < m; j++) {
                if (mat[i][j] == 'G') {
                    boolean curr = isPossible(i,j,cache,mat,moves,new boolean[n][m]);
                    cache[i][j]=curr?1:0;
                    ans = ans && curr;
                }
            }
        }

        return ans&&successfullyBlocked ? "Yes" : "No";
    }
    private static boolean isPossible(int x, int y, int[][] cache, char[][] mat, int[][] moves, boolean[][] visited) {
        int n = mat.length;
        int m = mat[0].length;
        if (x<0 || x >= n || y < 0 || y >= m || mat[x][y] == '#') return false;
        else if (x == n-1 && y == m-1) return true;
        else if (cache[x][y] != -1) return cache[x][y]==1;
        else {
            boolean ans = false;
            visited[x][y]=true;
            for (int[] move : moves) {
                int dx = x+move[0];
                int dy = y+move[1];
                if (dx>=0 && dx < n && dy >= 0 && dy < m && !visited[dx][dy]) {
                    ans = ans || isPossible(dx,dy,cache,mat,moves,visited);
                }
            }
            return ans;
        }
    }
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int t = Integer.parseInt(br.readLine());
		while(t-- > 0) {
		    StringTokenizer tok = new StringTokenizer(br.readLine());
		    int n = Integer.parseInt(tok.nextToken());
		    int m = Integer.parseInt(tok.nextToken());
		    char[][] mat = new char[n][m];
		    for(int i = 0; i < n; i++) {
		        String line = br.readLine();
		        for(int j = 0; j < m; j++) {
		            mat[i][j] = line.charAt(j);
		        }
		    }
		    System.out.println(process(mat));
		}
	}
}


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 {
                boolean stack=false;
                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]=='G')||(j-1>0&&s[i][j-1]=='G')||(i+1<n&&s[i+1][j]=='G')||(j+1<m&&s[i][j+1]=='G')) {
                                    stack=true;
                                } else {
                                    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]='#';
                                }
                            }
                        }
                    }
                }
                if(stack) out.println("NO");
                else {
                    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;
        }
    }
}