#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define mod 1000000007ll
#define mod1 998244353ll
#define endl '\n'
#define inf ((ll)1e5+1)
#include<chrono>
using namespace chrono;
mt19937_64 rng(high_resolution_clock::now().time_since_epoch().count());
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update>
#define debr(x,y) {cout<<"-->  "<<#x<<" to "<<#y<<" :  "; auto itr=x; while(itr!=y) cout<<(*itr++)<<' '; cout<<endl; }
#define deba(x) {cout<<"-->  "<<#x<<" :  "; for(auto ele:(x)) cout<<ele<<"  "; cout<<endl; }
#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s);istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout<<endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a <<"  ,  ";
    err(++it, args...);
}



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll t;
    cin>>t;
    while(t--){
        ll n,m;
        cin>>n>>m;
        vector<string> ar(n);
        ll good=0;
        for(int x=0;x<n;x++){
            cin>>ar[x];
            for(int y=0;y<m;y++){
                if(ar[x][y]=='G')good++;
            }
        }
        if(good==0){
            cout<<"YES"<<endl;
            continue;
        }
        bool poss=1;
        for(int x=0;x<n;x++){
            for(int y=0;y<m;y++){
                if(ar[x][y]=='G'){
                    for(int x1:{-1,1}){
                        int xnew=x+x1;
                        if(xnew>=0 && xnew<n && ar[xnew][y]=='B'){
                            poss=0;
                            break;
                        }
                    }
                    for(int y1:{-1,1}){
                        int ynew=y+y1;
                        if(ynew>=0 && ynew<m && ar[x][ynew]=='B'){
                            poss=0;
                            break;
                        }
                    }
                }
                if(!poss)break;
            }
            if(!poss)break;
        }
        // deb(poss);
        if(!poss){
            cout<<"NO"<<endl;
            continue;
        }
        for(int x=0;x<n;x++){
            for(int y=0;y<m;y++){
                if(ar[x][y]=='B'){
                    for(int x1:{-1,1}){
                        int xnew=x+x1;
                        if(xnew>=0 && xnew<n){
                            ar[xnew][y]='#';
                        }
                    }
                    for(int y1:{-1,1}){
                        int ynew=y+y1;
                        if(ynew>=0 && ynew<m){
                            ar[x][ynew]='#';
                        }
                    }
                }
            }
        }
        if(ar[n-1][m-1]=='#'){
            cout<<"NO"<<endl;
            continue;
        }
        vector<ll> dist[n];
        for(int x=0;x<n;x++){
            dist[x].resize(m,inf);
        }
        dist[n-1][m-1]=0;
        queue<pair<ll,ll>> q;
        q.push({n-1,m-1});
        while(!q.empty()){
            auto pa=q.front();
            q.pop();
            int x=pa.first;
            int y=pa.second;
            for(int x1:{-1,1}){
                int xnew=x+x1;
                if(xnew>=0 && xnew<n && ar[xnew][y]!='#' && dist[xnew][y]>dist[x][y]+1){
                    dist[xnew][y]=dist[x][y]+1;
                    q.push({xnew,y});
                }
            }
            for(int y1:{-1,1}){
                int ynew=y+y1;
                if(ynew>=0 && ynew<m && ar[x][ynew]!='#' && dist[x][ynew]>dist[x][y]+1){
                    dist[x][ynew]=dist[x][y]+1;
                    q.push({x,ynew});
                }
            }
        }
        for(int x=0;x<n;x++){
            for(int y=0;y<m;y++){
                if(ar[x][y]=='G'){
                    if(dist[x][y]==inf){
                        poss=0;
                        break;
                    }
                }else if(ar[x][y]=='B'){
                    if(dist[x][y]<inf){
                        poss=0;
                        break;
                    }
                }
            }
            if(!poss)break;
        }
        if(poss){
            cout<<"YES"<<endl;
        }else{
            cout<<"NO"<<endl;
        }
    }
    return 0;
}