
// Problem : D. Solve The Maze
// Contest : Codeforces - Codeforces Round #648 (Div. 2)
// URL : https://codeforces.com/contest/1365/problem/D
// Memory Limit : 256 MB
// Time Limit : 1000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll int
#define endl '\n'
#define pb push_back
#define mod 1000000007
ll power(ll x, ll y) 
{ 
    if (y == 0) 
        return 1; 
    ll p = power(x, y/2) % mod; 
    p = (p * p) % mod; 
  
    return (y%2 == 0)? p : (x * p) % mod; 
} 
ll factorial[1000007];
ll fact(ll n)
{
    memset(factorial,0,sizeof(factorial));
    factorial[0]=1;
factorial[1]=1;

    for(int i=1;i<n;i++)
    {
        factorial[i]=(factorial[i-1]*i)%mod;
    }
    
}
ll ncr(ll n,ll r)
{
    ll ans=1;
    ll i;
    ans=factorial[n];
    ll ans1=power(factorial[n-r],mod-2);
    ll ans2=power(factorial[r],mod-2);
    ans=((ans*ans1)%mod*ans2)%mod;
    return ans;
}
ll gcd(ll a, ll b) 
{ 
    if (b == 0) 
        return a; 
    return gcd(b, a % b);  
      
} 

bool prime[100000006];
void sieve(ll n){
    memset(prime,true,sizeof(prime));
	prime[1]=false; 
    for (ll p=2;p*p<=n;p++){
        if (prime[p]){  
            for (ll i=p*p;i<=n;i+=p)
                prime[i]=false;
        }
    }
}
void bfs(vector<int> v[],int o,int n,int dp[]){
	queue<int> q;
	q.push(o);
	dp[o]=0;
	bool visited[n+1]={0};
	visited[o]=true;
	while(q.empty()==false){
		int a=q.front();
		q.pop();
		for(int i=0;i<v[a].size();i++){
			if(visited[v[a][i]]==false){
				visited[v[a][i]]=true;
				q.push(v[a][i]);
				dp[v[a][i]]=dp[a]+1;
			}
		}
	}
}
int nov[1000001];
bool visited[1000001];
int dp[1000001];
int dfs(vector<int> v[],int o)
{
    if(visited[o]==0)
    {
        visited[o]=1;
        for(int i=0;i<v[o].size();i++)
        {
            if(visited[v[o][i]]==0)
            {
            dp[v[o][i]]=dp[o]+1;
            nov[o]+=dfs(v,v[o][i]);
            }
        }
        return nov[o]+1;
    }
    else
    return 0;
}
// string s=bitset<64>(n).to_string();
bool recurs(int i,int j,vector<vector<char>>& arr)
{
	 //directions 
    int dir[4][2] = { {0,1}, {0,-1}, {1,0}, {-1,1}}; 
      
    //queue  
    queue<pair<int,int> > q; 
      
    //insert the top right corner. 
    q.push(make_pair(i,j)); 
      
    //until queue is empty 
    while(q.size()>0) 
    { 
        pair<int, int> p = q.front(); 
        q.pop(); 
          
        //mark as visited 
        arr[p.first][p.second] = '#'; 
          
        //destination is reached. 
        if(p == make_pair((int)arr.size()-1,(int)arr[0].size()-1)) 
            return true; 
              
        //check all four directions 
        for(int i=0; i<4 ;i++) 
        { 
            //using the direction array 
            int a = p.first + dir[i][0]; 
            int b = p.second + dir[i][1]; 
              
            //not blocked and valid 
            if( a>=0 && b>=0 
                    && a<arr.size()&& b<arr[0].size()&&arr[a][b]!='#'&&arr[a][b]!='B') 
            { 
                q.push(make_pair(a,b)); 
            } 
        } 
    } 
    return false;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
	ll t;
	cin>>t;
	while(t--)
	{
		ll n,m;
		cin>>n>>m;
		vector<vector<char>> a(n,vector<char>(m));
		vector<vector<char>> z;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<m;j++)
			{
				cin>>a[i][j];
			}
		}
		map<pair<ll,ll>,ll> g;
		map<pair<ll,ll>,ll> b;
		for(int i=0;i<n;i++)
		{
			for(int j=0;j<n;j++)
			{
				if(a[i][j]=='G')
				g[{i,j}]=1;
				else if(a[i][j]=='B')
				b[{i,j}]=1;
			}
		}
		if(g.size()==0&&b.size()==0)
		cout<<"Yes"<<endl;
		else if(g.size()==0)
		cout<<"Yes"<<endl;
		else
		{
			int bol=0;
			if(b.size()>0)
			{
			for(auto itr=b.begin();itr!=b.end();itr++)
			{
				pair<ll,ll> temp=itr->first;
				if(temp.first+1<n)
				{
					if(g.find({temp.first+1,temp.second})!=g.end())
					{
						bol=1;
						break;
					}
					else
					a[temp.first+1][temp.second]='#';
				}
				if(g.find({temp.first,temp.second})!=g.end())
				{
					bol=1;
					break;
				}
				if(temp.first-1>=0)
				{
					if(g.find({temp.first-1,temp.second})!=g.end())
					{
						bol=1;
						break;
					}
					else
					a[temp.first-1][temp.second]='#';
				}
				if(temp.second+1<m)
				{
					if(g.find({temp.first,temp.second+1})!=g.end())
					{
						bol=1;
						break;
					}
					else
					a[temp.first][temp.second+1]='#';
				}
				if(temp.second-1>=0)
				{
					if(g.find({temp.first,temp.second-1})!=g.end())
					{
						bol=1;
						break;
					}
					else
					a[temp.first][temp.second-1]='#';
				}
			}
			}
			if(bol==1)
			cout<<"No"<<endl;
			else
			{
				for(auto itr=g.begin();itr!=g.end();itr++)
				{
					pair<ll,ll> temp=itr->first;
					z=a;
				if(!recurs(temp.first,temp.second,z))
			    {
				   bol=1;
				   break;
				}
				}
				if(bol==0)
				cout<<"Yes"<<endl;
				else
				cout<<"No"<<endl;
			}
		}
		
	}
	return 0;
}
