#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define zad tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
using namespace std;

#define in1(x) scanf("%lld",&x)
#define in2(x,y) scanf("%lld%lld",&x,&y)
#define in3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define out(x) printf("%lld",x)
#define outspace(x) printf("%lld ",x)
#define outln(x) printf("%lld\n",x)

#define ll long long
#define ld long double
#define pb push_back
#define p push
#define mkp make_pair
#define ff first
#define PLL pair<ll,ll>
#define PSS pair<string,string>
#define ss second
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define minQueue priority_queue<PLL,vector<PLL>,greater<PLL> >
#define maxQueue priority_queue<ll,vector<ll>,less<ll> >
#define all(x) x.begin(),x.end()
#define F(i,a,b) for(ll i=a;i<b;i++)
#define RF(i,a,b) for(ll i=a;i>b;i--)
#define mset(a,b) memset((a),(b),sizeof((a)))
#define IOS ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
#define MOD 1000000007
#define RMOD 998244353
#define INF 10000000000000000
#define MINF LONG_LONG_MIN
#define MAXF LONG_LONG_MAX
const ll N=1000002;
#define OuterLoop ll t;scanf("%lld",&t);while(t--)
#define lcm(a,b) a*b/(__gcd(a,b))
bool isPrime(ll n){
    if (n <= 1)  return false;
    if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
    ll p=sqrt(n);
    for(int i=5;i<=p;i+=6)
        if (n%i == 0 || n%(i+2) == 0)
            return false;
    return true;
}
ll power(ll a , ll b)
{
    ll result = 1;
    while(b > 0)
    {
        if(b%2 == 1) result = (result * a)%MOD;
        a = (a * a)%MOD;
        b = b/2;
    }
    return result%MOD;
}

struct DSU
{
        int parent[2600],size[2600];
        void init(int n)
        {
            for(int i=1;i<=n;i++)
            {
                parent[i]=i;
                size[i]=1;
            }
        }
        
        int getParent(int k)
        {
            while(k != parent[k])
            {
                parent[k]=parent[parent[k]];
                k= parent[k];
            }
            return k;
        }
        
        int getSize(int m)
        {
            return size[getParent(m)];
        }
        
        void unioon(int x,int y)
        {
            int p1= getParent(x);
            int p2= getParent(y);
            
            if(p1==p2)
            {
                return;
            }
            if(size[p1]>size[p2])
            {
                parent[p2]=p1;
            }
            else if(size[p2]>size[p1])
            {
                parent[p1]=p2;
            }
            else
            {
                parent[p2]=p1;
                size[p1]++;
            }    
        }
};


void solve(ll pp)
{ 
    ll n,m,cnt=0;
    cin >> n >> m;
    string s[n];
    for(ll i=0;i<n;i++) cin>>s[i];

    for(ll i=0;i<n;i++)
    {
        for(ll j=0;j<m;j++)
        {
            if(s[i][j]=='B')
            {
                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(i-1>=0 && s[i-1][j]=='.') s[i-1][j]='#';
                if(j-1>=0 && s[i][j-1]=='.') s[i][j-1]='#';
            }
            else if(s[i][j]=='G') cnt++;
        }
    }
    
    if(s[n-1][m-1]=='#' && cnt) cout<<"No\n";
    else if(!cnt) cout<<"Yes\n";
    else
    {
        DSU d;
        d.init(n*m);
        for(ll i=n-1;i>=0;i--)
        {
            for(ll j=m-1;j>=0;j--)
            {
                if(s[i][j]!='#')
                {
                    if(i+1<n && s[i+1][j]!='#')
                    {
                        
                        d.unioon(i*m+j,(i+1)*m + j);
                    }
                    if(j+1<m && s[i][j+1]!='#')
                    {
                        
                        d.unioon(i*m+j,(i)*m + j+1);
                    }
                    if(i-1>=0 && s[i-1][j]!='#')
                    {
                        
                        d.unioon(i*m+j,(i-1)*m + j);
                    }
                    if(j-1>=0 && s[i][j-1]!='#') 
                    {
                        
                        d.unioon(i*m+j,(i)*m + j-1);
                    }
                }
            }
        }
        ll x=(n-1)*m+(m-1);
        for(ll i=0;i<n;i++)
        {
            for(ll j=0;j<m;j++)
            {
                if(s[i][j]=='G')
                {
                    if(d.getParent(i*m+j)!=x) 
                    {
                        cout<<"No\n";
                        return;
                    }
                }
                else if(s[i][j]=='B')
                {
                    if(d.getParent(i*m+j)==x)
                    {
                        cout<<"No\n";
                        //cout << d.getParent(i*m+j) << " "<<i*m+j;
                        return;
                    }
                }
            }
        }

        cout<<"Yes\n";
        
    }
    
}
int main()
{
    IOS
    ll t=1;
    cin >> t;
    while(t)
    {
        solve(t--);
    }
}