#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define m_p make_pair
#define pb push_back 
#define ppb pop_back
#define f first
#define s second
#define pii pair<int,int>
#define ios ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define double long double
const double pi=3.14159265358979;
 
const int mod=1e9+7;
 
int takemod(int a,int m = mod)
{
  return ((a%m)+m)%m;
}
int power(int  b, int  p)
{
  if(p==0)return 1;
  else if(p%2==0)
  {
      int q=power(b,p/2);
      return ((q)*(q));
  }
  else return ((b)*(power(b,p-1)));
}
int powerm(int  b, int  p,int mod = mod)
{
  if(p==0)return 1;
  else if(p%2==0)
  {
      int q=powerm(b,p/2);
      return ((q%mod)*(q%mod))%mod;
  }
  else return ((b%mod)*(powerm(b,p-1)%mod))%mod;
}

bool isprime(int n)
{
  if(n==1)return false;
  if(n==2 or n==3)return true; 
  int  lim=sqrt(n); 
  int  i=2;
  while(i<=lim)
  {
      if(n%i==0)return false; 
      i++;
  }
  return true;
}
vector< int > factors( int  n)
{
  vector< int > a;
  a.pb(1);
  int  lim=sqrt(n);
  int i=2;
  while(i<=lim)
  {
      if(n%i==0)
      {
          a.pb(i);
          if(i!=n/i)a.pb(n/i);
      }
      i++;
  }

  if(n!=1)a.pb(n);
 // sort(a.begin(),a.end());
  return a;
}
vector<pii> pf_with_count(int  b)
{ 
  pii p;
  vector<pii>pf;
  int  count=0;
  while(b%2==0)
  {
    b/=2;
    count++;
  }
  if(count>0)
  {
    p.f=2;
    p.s=count;
    pf.pb(p);
  }
  int i=3;
  while(i<=sqrt(b))
  {
        count=0;
        while(b%i==0)
        {
            b/=i;
            count++;
        }
        if(count>0)
        {
            p.f=i;
            p.s=count;
            pf.pb(p);
        }
        i+=2;
  }
  if(b>2) 
  {
      p.f=b;
      p.s=1;
      pf.pb(p);
  } 
  sort(pf.begin(),pf.end());
  return pf;
}
int  bs_t_i(string s)
{
  int  l=strtoull(s.c_str(),NULL,2);
  return l;
}
string  i_to_bs(int  n)
{
  string s = bitset< 64 >( n ).to_string();
  return s;
}
int s_t_i(string s)
{
  stringstream obj(s); 
  int x = 0; 
  obj >> x; 
  return x;
}

//freopen("b_small.in","r", stdin);
 
 
  // ofstream outfile;
  // outfile.open("phele2.in"); 
  // outfile << 2*n << endl;
vector<int> v[2501];
map<pii,int> mp;
map<int,int> vis;

char a[51][51];
int gfoo=0;
void dfs(int i)
{
  vis[i]=1;

  int j=0;
  while(j<v[i].size())
  {
    if(!vis[v[i][j]])dfs(v[i][j]);
    j++;
  }
}
void sol()
{
  int n,m;
  cin>>n>>m;

  int i=0;
  int c=1;
  int cnt=0;
  while(i<n)
  {
    int j=0;
    while(j<m)
    {
      cin>>a[i][j];
      if(a[i][j]=='G')cnt++;
      mp[{i,j}]=c;
      c++;
      j++;
    }
    i++;
  }
  i=0;
  while(i<n)
  {
    int j=0;
    while(j<m)
    {
      if(a[i][j]!='#')
      {
        if(i-1>=0 and a[i-1][j]!='#')v[mp[{i,j}]].pb(mp[{i-1,j}]);
        if(i+1<n and a[i+1][j]!='#')v[mp[{i,j}]].pb(mp[{i+1,j}]);
        if(j-1>=0 and a[i][j-1]!='#')v[mp[{i,j}]].pb(mp[{i,j-1}]);
        if(j+1<m and a[i][j+1]!='#')v[mp[{i,j}]].pb(mp[{i,j+1}]);

      }
      j++;
    }
    i++;
  }
  i=0;
  while(i<n)
  {
    int j=0;
    while(j<n)
    {
       if(a[i][j]=='G')
       {
         vis.clear();
         dfs(mp[{i,j}]);
         if(!vis[mp[{n-1,m-1}]])
         {
           cout<<"No"<<endl;
           return;
         }
       }
       if(a[i][j]=='B')
       {
        gfoo=0;
        if(i-1>=0 and a[i-1][j]=='G')gfoo=1;
        if(i+1<n and a[i+1][j]=='G')gfoo=1;
        if(j-1>=0 and a[i][j-1]=='G')gfoo=1;
        if(j+1<m and a[i][j+1]=='G')gfoo=1;
        if(gfoo)
        {
          cout<<"No"<<endl;
          return;
        }
       }
       j++;
    }
    i++;
  }
  if(cnt>0)
  {
    if((n>1 and a[n-2][m-1]=='B')  or  (m>1 and a[n-1][m-2]=='B'))
    {
      cout<<"No"<<endl;
      return;
    }
  }
  if(cnt==0)
  {
    cout<<"Yes"<<endl;
    return;
  }
  i=0;
  while(i<n)
  {
    int j=0;
    while(j<m)
    {
      if(a[i][j]=='B')
      {
        if(i-1>=0 and a[i-1][j]!='B')a[i-1][j]='#';
        if(i+1<n and a[i+1][j]!='B' and !(i==n-2 and j==m-1))a[i+1][j]='#';
        if(j-1>=0 and a[i][j-1]!='B')a[i][j-1]='#';
        if(j+1<m and a[i][j+1]!='B' and !(i==n-1 and j==m-2))a[i][j+1]='#';    
      }
      j++;
    }
    i++;
  }
  i=0;
  while(i<=2500)
  {
    v[i].clear();
    i++;
  }
  i=0;
  while(i<n)
  {
    int j=0;
    while(j<m)
    {
      if(a[i][j]!='#')
      {
        if(i-1>=0 and a[i-1][j]!='#')v[mp[{i,j}]].pb(mp[{i-1,j}]);
        if(i+1<n and a[i+1][j]!='#')v[mp[{i,j}]].pb(mp[{i+1,j}]);
        if(j-1>=0 and a[i][j-1]!='#')v[mp[{i,j}]].pb(mp[{i,j-1}]);
        if(j+1<m and a[i][j+1]!='#')v[mp[{i,j}]].pb(mp[{i,j+1}]);

      }
      j++;
    }
    i++;
  }  
  vis.clear();
  i=0;
  while(i<n)
  {
    int j=0;
    while(j<n)
    {
       if(a[i][j]=='G')
       {
         vis.clear();
         dfs(mp[{i,j}]);
         if(!vis[mp[{n-1,m-1}]])
         {
           cout<<"No"<<endl;
           return;
         }
       }
       j++;
     }
     i++;
   }
   cout<<"Yes"<<endl;
}

signed main()
{
  ios;
  int t=1;
  cin>>t;
  while(t--)sol();
 
}