#include <map>
#include <set>
#include <vector>
#include <iostream>

using namespace std;

typedef long long ll;
typedef pair<int, int>pii;

const int MOD = 1e9 + 7;
const int MXN = 200005;

int dx[] = {-1, 0, 1};

bool withingRange(int x, int y, int N, int M) {
    if((x >= 0 && x < N) && (y >= 0 && y < M)) {
        return true;
    }
    return false;
}

void demarcate(vector<string> &mat, int x, int y, int N, int M) {
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            if(abs(dx[i]) == abs(dx[j])) {
                continue;
            }
            int newX = x + dx[i];
            int newY = y + dx[j];

            if(withingRange(newX, newY, N, M) && mat[newX][newY] == '.') {
                mat[newX][newY] = '#';
            }
        }
    }
}

void demarcateAdjacentToB(vector<string>& mat, int N, int M) {
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < M; j++) {
            if(mat[i][j] == 'B') {
                demarcate(mat, i, j, N, M);
            }
        }
    }
}

bool check(vector<string>& mat, int x, int y, int N, int M) {
    for(int i = 0; i < 3; i++) {
        for(int j = 0; j < 3; j++) {
            if(abs(dx[i]) == abs(dx[j])) {
                continue;
            }
            int newX = x + dx[i];
            int newY = y + dx[j];

            if(withingRange(newX, newY, N, M)) {
                if(mat[newX][newY] == 'G') {
                    return false;
                }
            }
        }
    }
    return true;
}

bool checkAdjacent(vector<string>& mat, int N, int M) {
    bool res = true;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < M; j++) {
            if(mat[i][j] == 'B') {
                res = res & check(mat, i, j, N, M);
            }
        }
    }
    return res;
}

bool checkPath(vector<string>& mat, int x, int y, int N, int M) {
    bool vis[N][M];
    vector<pii> myq;

    for(int i = 0; i < N; i++) {
        for(int j = 0; j < M; j++) {
            vis[i][j] = false;
        }
    }

    myq.push_back(make_pair(x, y));
    int siz = 1;
    while(siz > 0) {
        pii cell = myq[siz-1];
        x = cell.first;
        y = cell.second;
        vis[x][y] = true;

        myq.pop_back();

        // cout<<"x: "<<x<<" y: "<<y<<endl;
        siz--;

        for(int i = 0; i < 3; i++) {
            for(int j = 0; j < 3; j++) {
                if(abs(dx[i]) == abs(dx[j])) {
                    continue;
                }

                // cout<<"dx: "<<dx[i]<<" dy: "<<dx[j]<<endl;
                int newX = x + dx[i];
                int newY = y + dx[j];

                // cout<<"newX: "<<newX<<" newY: "<<newY<<endl;
                if(withingRange(newX, newY, N, M) && mat[newX][newY] != '#' && !vis[newX][newY]) {
                    myq.push_back(make_pair(newX, newY));
                    siz++;
                }
            }

        }
    }
    if(vis[N-1][M-1]) {
        return true;
    }
    return false;
}

void solve() {
    int N, M;
    vector<string>mat;
    string s;

    cin>>N >>M;

    for(int i = 0; i < N; i++) {
        cin>>s;
        mat.push_back(s);
    }

    if(!checkAdjacent(mat, N, M)) {
        cout<<"No"<<endl;
        return;
    }

    demarcateAdjacentToB(mat, N, M);

    bool res = true;
    for(int i = 0; i < N; i++) {
        for(int j = 0; j < M; j++) {
            if(mat[i][j] == 'G') {
                // cout<<"i: "<<i<<" j: "<<j<<" "<<checkPath(mat, i, j, N, M)<<endl;
                res = res & checkPath(mat, i, j, N, M);
            }
        }
    }

    if(res) {
        cout<<"Yes"<<endl;
    } else {
        cout<<"No"<<endl;
    }

    return;

}

int main() {
    int t;

    cin>>t;

    while(t--) {
        solve();
    }
}
