import java.util.*;

public class A {

    static class Pair {
        int x;
        int y;

        Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }

    static boolean poss(int n, int m, int row, int col) {
        if (row >= 0 && row < n && col >= 0 && col < m) {
            return true;
        }
        return false;
    }

    static boolean vis[][];
    static int count;
    static boolean can_vis;

    static void dfs(char mat[][], int n, int m, int row, int col) {
        vis[row][col] = true;

        if (mat[row][col] == 'G') {
            count++;
        }

        if (row == n - 1 && col == m - 1) {
            can_vis = true;
        }

        col--;
        if (poss(n, m, row, col) && !vis[row][col] && mat[row][col] != 'B' && mat[row][col] != '#') {
            dfs(mat, n, m, row, col);
        }

        col = col + 2;
        if (poss(n, m, row, col) && !vis[row][col] && mat[row][col] != 'B' && mat[row][col] != '#') {
            dfs(mat, n, m, row, col);

        }

        col--;
        row--;
        if (poss(n, m, row, col) && !vis[row][col] && mat[row][col] != 'B' && mat[row][col] != '#') {
            dfs(mat, n, m, row, col);

        }

        row = row + 2;
        if (poss(n, m, row, col) && !vis[row][col] && mat[row][col] != 'B' && mat[row][col] != '#') {
            dfs(mat, n, m, row, col);

        }

        row--;

    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        int testCases = sc.nextInt();

        for (int t = 0; t < testCases; t++) {
            int n = sc.nextInt();
            int m = sc.nextInt();

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

            ArrayList<Pair> al = new ArrayList<>();

            int count_G = 0;

            for (int i = 0; i < n; i++) {
                String str = sc.next();
                mat[i] = str.toCharArray();
                for (int j = 0; j < m; j++) {
                    if (mat[i][j] == 'B') {
                        al.add(new Pair(i, j));
                    }

                    if (mat[i][j] == 'G') {
                        count_G++;
                    }

                }
            }

            boolean poss = true;

            for (int i = 0; i < al.size(); i++) {
                Pair cur = al.get(i);
                int row = cur.x;
                int col = cur.y;

                col--;
                if (poss(n, m, row, col)) {
                    if (mat[row][col] == 'G') {
                        poss = false;
                        break;
                    }
                    mat[row][col] = '#';
                }

                col = col + 2;
                if (poss(n, m, row, col)) {
                    if (mat[row][col] == 'G') {
                        poss = false;
                        break;
                    }
                    mat[row][col] = '#';
                }

                col--;
                row--;
                if (poss(n, m, row, col)) {
                    if (mat[row][col] == 'G') {
                        poss = false;
                        break;
                    }
                    mat[row][col] = '#';
                }

                row = row + 2;
                if (poss(n, m, row, col)) {
                    if (mat[row][col] == 'G') {
                        poss = false;
                        break;
                    }
                    mat[row][col] = '#';
                }

                row--;

            }

            if (!poss) {
                sb.append("NO").append("\n");
                continue;
            }

            if (al.size() == 0) {
                sb.append("YES").append("\n");
                continue;
            }

            vis = new boolean[n][m];
            count = 0;
            can_vis = false;

            first: for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (mat[i][j] == 'G') {
                        dfs(mat, n, m, i, j);
                        break first;
                    }
                }
            }

            if ((count == count_G && can_vis) || count == 0) {
                sb.append("YES").append("\n");
                continue;
            }

            sb.append("NO").append("\n");

        }

        System.out.print(sb);
    }
}