#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define mt              make_tuple
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define range(a,b)		  substr(a,b-a+1)
#define w(x)            int x; cin>>x; while(x--)
#define trace(x) 		  cerr<<#x<<": "<<x<<" "<<endl;
#define FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

string s[10000];
int n, m;
int vis[1000][1000] = {};

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

bool is_valid(int x, int y)
{
	if(x < 0 || x >= n || y < 0 || y >= m)
		return false;

	if(vis[x][y] || s[x][y] == '#')
		return false;

	return true;
}

bool bfs(int x, int y)
{
	if(x == n - 1 and y == m - 1)
		return true;

	queue<pair<int, int >> q;

	q.push({x, y});
	vis[x][y] = 1;

	while(!q.empty())
	{
		pair<int, int> p = q.front();
		q.pop();

		for(int i = 0; i < 4; ++i)
		{
			int first = dx[i] + p.ff, second = dy[i] + p.ss;
			if(is_valid(first, second))
			{
				if(first == n - 1 and second == m - 1)
					return true;

				vis[first][second] = 1;
				q.push({first, second});
			}
		}
	}

	return false;
}


int32_t main()
{
	FIO;
	w(t)
	{
		cin >> n >> m;
		for(int i = 0; i < n; ++i)
			cin >> s[i];

		int good = 0, bad = 0;
		set<pair<int, int >> g, b, e;

		for(int i = 0; i < n; ++i)
			for(int j = 0; j < m; ++j)
			{
				if(s[i][j] == 'G')
					++good, g.insert({i, j});

				else if(s[i][j] == 'B')
					++bad, b.insert({i, j});

				else if(s[i][j] == '.')
					e.insert({i, j});
			}

		if((!good && s[n - 1][m - 1] != 'B') or (!good && !bad))
		{
			cout << "Yes\n";
			continue;
		}

		if(s[n - 1][m - 1] == 'B')
		{
			cout << "No\n";
			continue;
		}

		int psbl = 1;
		for(auto& e : g)
		{
			for(int i = 0; i < n; ++i)
				for(int j = 0; j < m; ++j)
					vis[i][j] = 0;

			bool can = bfs(e.ff, e.ss);
			if(!can)
			{
				psbl = 0;
				break;
			} 

		}

		if(!psbl)
		{
			cout << "No\n";
			continue;
		}

		for(auto& r : e)
		{
			s[r.ff][r.ss] = '#';
			bool psbl = 1;
			for(auto& x : g)
			{
				for(int i = 0; i < n; ++i)
					for(int j = 0; j < m; ++j)
						vis[i][j] = 0;

				psbl = bfs(x.ff, x.ss);
				if(!psbl) break;


			} 

			if(!psbl)
				s[r.ff][r.ss] = '.';
		}

		psbl = 1;
		for(auto& e : b)
		{
			for(int i = 0; i < n; ++i)
				for(int j = 0; j < m; ++j)
					vis[i][j] = 0;

			bool can = bfs(e.ff, e.ss);
			if(can)
			{
				psbl = 0;
				break;
			}

		}

		if(psbl)
			cout << "Yes\n";
		else
			cout << "No\n";
	}
	return 0;
}