#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#include <chrono> 
using namespace std::chrono;
using namespace std;
typedef long long ll;
using namespace __gnu_pbds;   
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 
#define ordered_mset tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> 
#define fr(i,a,b) for (ll i=(a); i<(b);i++)
#define frr(i,a,b) for(ll i=(a-1);i>=(b);i--)
#define vi vector<int>
#define vl vector<ll>
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define F first
#define S second
#define pii pair<int,int> 
#define rev(a) reverse(a.begin(),a.end())
#define srt(a) sort(a.begin(),a.end())
#define rsrt(a) sort(a.begin(),a.end(),greater<int>())
#define sz(a) (ll)a.size()
#define endl "\n"

#define print(a) for(auto x:a)cout<<x<<" ";cout<<endl;
#define print2(a) for(auto x:a){for(auto y:x)cout<<y<<" ";cout<<endl;}; 
void read(int &number){bool negative=false;register int c;number=0; c=getchar();if (c=='-'){negative=true;c=getchar();}for(;(c>47&&c<58);c=getchar())number=number*10+c-48;if(negative)number*= -1;}
const ll M=1e9+9;
const int P=29;
const int MaxM=100005;
const double pi=acos(-1);

int n,m;
char grid[51][51];
int vis[51][51];
int num;
int flag;
bool in(int i,int j){
    if(i<1 || j<1 || i>n || j>m)return false;
    return true;
}

bool safe(int i,int j)
{   
    if(grid[i][j]=='#')return false;
    if(in(i,j-1) && grid[i][j-1]=='B')return false;
    if(in(i-1,j) && grid[i-1][j]=='B')return false;
    if(in(i,j+1) && grid[i][j+1]=='B')return false;
    if(in(i+1,j) && grid[i+1][j]=='B')return false;
    return true;
}

void check(int i,int j){

         if(vis[i][j]==num)return;
        if(i==n && j==m){flag=1;return;}
       vis[i][j]=num;
       if(in(i-1,j) && safe(i-1,j))check(i-1,j);
       if(in(i,j-1) && safe(i,j-1))check(i,j-1);
       if(in(i+1,j) && safe(i+1,j))check(i+1,j);
       if(in(i,j+1) && safe(i,j+1))check(i,j+1);
}


int main()
{ios_base::sync_with_stdio(false);
 cin.tie(NULL);cout.tie(NULL);
    
      #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

   int t;
   cin>>t;
   while(t--)
   {
      
      cin>>n>>m;
      memset(vis,-1,sizeof vis);
 int c=1;
      vector<pii> v;
      fr(i,1,n+1)
      fr(j,1,m+1)
      {cin>>grid[i][j];if(grid[i][j]=='G'){v.pb({i,j});if(!safe(i,j))c=0;}}

      if(!c){cout<<"NO"<<endl;}
      else
      {  int cnt=0;
         fr(i,0,sz(v))
         {  
            num=i+1;flag=0;
            check(v[i].F,v[i].S);
            if(flag)cnt++;
            else break;
         }
         if(cnt==sz(v))cout<<"YES"<<endl;
         else cout<<"NO"<<endl;
      }
      


   }
   
}