#include<bits/stdc++.h>
#define int long long
#define ll long long
#define speed ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define fs first
#define sd second
#define rept(x,n) for(int i=x;i<n;i++)
#define rrept(n,x) for(int i=n-1;i>=x;i--)
#define all(v) v.begin(),v.end()
#define mpit map<int,int>::iterator
#define stit set<int,int>::iterator
#define quit queue<int,int>::iterator
#define maxt(a,b,c) max(a,max(b,c))
#define mint(a,b,c) min(a,min(b,c))
#define rsort(v) sort(v.rbegin(),v.rend())
#define pb push_back
#define printarr(a,n) for(int i=0;i<n;i++)cout<<a[i]<<" ";cout<<"\n";
#define printvec(v) for(int i = 0;i<v.size();i++)cout<<v[i]<<" ";cout<<"\n";
using namespace std;
ll power(ll a,ll b){ll res = 1;while(b){if(b&1)res*=a;a*=a;b/=2;}return res;}
ll powerwithmod(ll a,ll b,ll mod){ll res = 1;while(b){if(b&1)res*=a;res%=mod;a*=a;a%=mod;b/=2;}return res;}
void sieve(vector<ll>&prime,ll n){ll candidate[n+1]={0};candidate[0]=1;candidate[1]=1;candidate[2]=0;
for(ll i = 4;i<=n;i+=2)candidate[i]=1;for(ll i = 3;i*i<=n;i+=2){if(candidate[i]==0){
for(ll j = i*i;j<=n;j+=i){candidate[j] = 1;}}}for(ll i = 2;i<=n;i++){if(candidate[i]==0)prime.pb(i);}}

/*-------------------------------------------------------------------------------------------------------*/
ll hor[]={1,-1,0,0};
ll ver[]={0,0,1,-1};
ll vis[50][50];
char arr[50][50];
ll n,m;
void dfs(ll a,ll b)
{
    if(arr[a][b]=='#')
        return;
    vis[a][b] = 1;
    for(ll i = 0;i<4;i++)
    {
        ll x = a + hor[i];
        ll y = b + ver[i];
        if(x<0||y<0||x>=n||y>=m||vis[x][y]==1)
            continue;
        dfs(x,y);
    }
}
void solve()
{
    memset(vis,0,sizeof(vis));
    cin>>n>>m;
    for(ll i = 0;i<n;i++)
    {
        for(ll j = 0;j<m;j++)
        {
            cin>>arr[i][j];
        }
    }
    for(ll i = 0;i<n;i++)
    {
        for(ll j = 1;j<m;j++)
        {
            if(arr[i][j]=='B'&&arr[i][j-1]=='G')
            {
                cout<<"No\n";
                return;
            }
            else if(arr[i][j]=='G'&&arr[i][j-1]=='B')
            {
                cout<<"NO\n";
                return;
            }
        }
    }
    for(ll i = 0;i<n;i++)
    {
        for(ll j = 0;j<m;j++)
        {
            if(arr[i][j]=='B')
            {
                if(j+1<m&&arr[i][j+1]=='.')
                    arr[i][j+1]='#';
                if(j-1>=0&&arr[i][j-1]=='.')
                    arr[i][j-1] = '#';
                if(i+1<n&&arr[i+1][j]=='.')
                    arr[i+1][j] = '#';
                if(i-1>=0&&arr[i-1][j]=='.')
                    arr[i-1][j]='#';
            }
        }
    }
    dfs(n-1,m-1);
    for(ll i = 0;i<n;i++)
    {
        for(ll j = 0;j<m;j++)
        {
            if(arr[i][j]=='G'&&vis[i][j]==0)
            {
                cout<<"NO\n";
                return;
            }
        }
    }
    cout<<"YES\n";
}
signed main()
{
    speed;
    int t=1;
    cin>>t;
    while(t--)
    {
         solve();
    }
    return 0;
}
