#include <bits/stdc++.h>
#define pi pair<int, int>
#define x first
#define y second
using namespace std;
int main()
{
int t;
cin>>t;
std::vector<string> re;
for(int i=0;i<t;i++){
int n,m;
cin>>n>>m;
char ar[n][m];
bool v[n][m];
int numG=0,numB=0;
for(int j=0;j<n;j++){
for(int k=0;k<m;k++){
v[j][k] = false;
cin>>ar[j][k];
if(ar[j][k]=='G') numG++;
else if(ar[j][k]=='B') numB++;
else if(ar[j][k]=='#') v[j][k] = true;
}
}
// cout<<"\n-----------------------------------------------------\n";
// for(int j=0;j<n;j++){
// cout<<"\n";
// for(int k=0;k<m;k++){
// cout<<" "<<ar[j][k];
// }
// }
bool needBreak = false;
if(numG==0) {
re.push_back("Yes");
needBreak = true;
continue;
}
int dx[] = {0,0,1,-1};
int dy[] = {1,-1,0,0};
for(int j=0;j<n;j++){
for(int k=0;k<m;k++){
if(ar[j][k]=='B'){
if(needBreak) break;
v[j][k] = true;
for(int h=0;h<4;h++){
//cout<<"\n j "<<j<<" k "<<k <<" h "<<h;
int x = j+dx[h];
int y = k+dy[h];
if(x<0 || y<0||x>=n||y>=m) continue;
//cout<<"\n --> x "<<x<<" y "<<y;
if(ar[x][y]=='G') {
needBreak = true;
re.push_back("No");
//cout<<"\n -->break: x "<<x<<" y "<<y;
break;
} else if(ar[x][y]=='.') {
ar[x][y]='#';
v[x][y] = true;
}
}
}
}
}
if(needBreak) continue;
else {
if(ar[n-1][m-1]=='#'){
re.push_back("No");
continue;
}
int count = 0;
std::queue<pi> q ;
q.push({n-1, m-1});
v[n-1][m-1] = true;
while(!q.empty()){
pi top = q.front();
q.pop();
for(int h=0;h<4;h++){
//cout<<"\n j "<<j<<" k "<<k <<" h "<<h;
int x = top.x+dx[h];
int y = top.y+dy[h];
if(x<0 || y<0||x>=n||y>=m || v[x][y]) continue;
//cout<<"\n --> x "<<x<<" y "<<y;
q.push({x,y});
v[x][y] = true;
if(ar[x][y]=='G') {
count++;
//cout<<"\n -->break: x "<<x<<" y "<<y;
}
}
}
if(count>=numG) re.push_back("Yes");
else re.push_back("No");
}
}
for(auto s:re){
cout<<s<<"\n";
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgcGkgcGFpcjxpbnQsIGludD4KI2RlZmluZSB4IGZpcnN0CiNkZWZpbmUgeSBzZWNvbmQKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpCnsKICAgIGludCB0OwogICAgY2luPj50OwogICAgc3RkOjp2ZWN0b3I8c3RyaW5nPiByZTsKICAgIGZvcihpbnQgaT0wO2k8dDtpKyspewogICAgICAgIGludCBuLG07CiAgICAgICAgY2luPj5uPj5tOwogICAgICAgIGNoYXIgYXJbbl1bbV07CiAgICAgICAgYm9vbCB2W25dW21dOwogICAgICAgIGludCBudW1HPTAsbnVtQj0wOwogICAgICAgIAogICAgICAgIGZvcihpbnQgaj0wO2o8bjtqKyspewogICAgICAgICAgZm9yKGludCBrPTA7azxtO2srKyl7CiAgICAgICAgICAgICAgdltqXVtrXSA9IGZhbHNlOwogICAgICAgICAgICAgIGNpbj4+YXJbal1ba107CiAgICAgICAgICAgICAgaWYoYXJbal1ba109PSdHJykgbnVtRysrOwogICAgICAgICAgICAgIGVsc2UgaWYoYXJbal1ba109PSdCJykgbnVtQisrOwogICAgICAgICAgICAgIGVsc2UgaWYoYXJbal1ba109PScjJykgIHZbal1ba10gPSB0cnVlOwogICAgICAgICAgICAgIAogICAgICAgICAgfSAgCiAgICAgICAgfQogICAgICAgIAogICAgICAgIC8vIGNvdXQ8PCJcbi0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tXG4iOwogICAgICAgIC8vIGZvcihpbnQgaj0wO2o8bjtqKyspewogICAgICAgIC8vICAgICBjb3V0PDwiXG4iOwogICAgICAgIC8vICAgZm9yKGludCBrPTA7azxtO2srKyl7CiAgICAgICAgLy8gICAgICBjb3V0PDwiICI8PGFyW2pdW2tdOwogICAgICAgICAgICAgIAogICAgICAgIC8vICAgfSAgCiAgICAgICAgLy8gfQogICAgICAgIAogICAgICAgIGJvb2wgbmVlZEJyZWFrID0gZmFsc2U7CiAgICAgICAgaWYobnVtRz09MCkgewogICAgICAgICAgICByZS5wdXNoX2JhY2soIlllcyIpOwogICAgICAgICAgICBuZWVkQnJlYWsgPSB0cnVlOwogICAgICAgICAgICBjb250aW51ZTsKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgaW50IGR4W10gPSB7MCwwLDEsLTF9OwogICAgICAgIGludCBkeVtdID0gezEsLTEsMCwwfTsKICAgICAgICAKICAgICAgICAKICAgICAgICAKICAgICAgICBmb3IoaW50IGo9MDtqPG47aisrKXsKICAgICAgICAgIGZvcihpbnQgaz0wO2s8bTtrKyspewogICAgICAgICAgICAgIGlmKGFyW2pdW2tdPT0nQicpewogICAgICAgICAgICAgICAgICBpZihuZWVkQnJlYWspIGJyZWFrOwogICAgICAgICAgICAgICAgICB2W2pdW2tdID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgZm9yKGludCBoPTA7aDw0O2grKyl7CiAgICAgICAgICAgICAgICAgICAgICAvL2NvdXQ8PCJcbiBqICI8PGo8PCIgayAiPDxrIDw8IiBoICI8PGg7CiAgICAgICAgICAgICAgICAgICAgICBpbnQgeCA9IGorZHhbaF07CiAgICAgICAgICAgICAgICAgICAgICBpbnQgeSA9IGsrZHlbaF07CiAgICAgICAgICAgICAgICAgICAgICBpZih4PDAgfHwgeTwwfHx4Pj1ufHx5Pj1tKSBjb250aW51ZTsKICAgICAgICAgICAgICAgICAgICAgIC8vY291dDw8IlxuIC0tPiB4ICI8PHg8PCIgeSAiPDx5OwogICAgICAgICAgICAgICAgICAgICAgaWYoYXJbeF1beV09PSdHJykgewogICAgICAgICAgICAgICAgICAgICAgICAgIG5lZWRCcmVhayA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgICAgICAgcmUucHVzaF9iYWNrKCJObyIpOwogICAgICAgICAgICAgICAgICAgICAgICAgIC8vY291dDw8IlxuIC0tPmJyZWFrOiB4ICI8PHg8PCIgeSAiPDx5OwogICAgICAgICAgICAgICAgICAgICAgICAgIGJyZWFrOwogICAgICAgICAgICAgICAgICAgICAgfSBlbHNlIGlmKGFyW3hdW3ldPT0nLicpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBhclt4XVt5XT0nIyc7CiAgICAgICAgICAgICAgICAgICAgICAgICAgdlt4XVt5XSA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICB9CiAgICAgICAgICB9ICAKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgaWYobmVlZEJyZWFrKSBjb250aW51ZTsKICAgICAgICBlbHNlIHsKICAgICAgICAgICAgaWYoYXJbbi0xXVttLTFdPT0nIycpewogICAgICAgICAgICAgICAgcmUucHVzaF9iYWNrKCJObyIpOwogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaW50IGNvdW50ID0gMDsKICAgICAgICAgICAgc3RkOjpxdWV1ZTxwaT4gcSA7CiAgICAgICAgICAgIHEucHVzaCh7bi0xLCBtLTF9KTsKICAgICAgICAgICAgdltuLTFdW20tMV0gPSB0cnVlOwogICAgICAgICAgICB3aGlsZSghcS5lbXB0eSgpKXsKICAgICAgICAgICAgICAgIHBpIHRvcCA9IHEuZnJvbnQoKTsKICAgICAgICAgICAgICAgIHEucG9wKCk7CiAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgIGZvcihpbnQgaD0wO2g8NDtoKyspewogICAgICAgICAgICAgICAgICAgICAgLy9jb3V0PDwiXG4gaiAiPDxqPDwiIGsgIjw8ayA8PCIgaCAiPDxoOwogICAgICAgICAgICAgICAgICAgICAgaW50IHggPSB0b3AueCtkeFtoXTsKICAgICAgICAgICAgICAgICAgICAgIGludCB5ID0gdG9wLnkrZHlbaF07CiAgICAgICAgICAgICAgICAgICAgICBpZih4PDAgfHwgeTwwfHx4Pj1ufHx5Pj1tIHx8IHZbeF1beV0pIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgICAgICAgLy9jb3V0PDwiXG4gLS0+IHggIjw8eDw8IiB5ICI8PHk7CiAgICAgICAgICAgICAgICAgICAgICBxLnB1c2goe3gseX0pOwogICAgICAgICAgICAgICAgICAgICAgdlt4XVt5XSA9IHRydWU7CiAgICAgICAgICAgICAgICAgICAgICBpZihhclt4XVt5XT09J0cnKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgY291bnQrKzsKICAgICAgICAgICAgICAgICAgICAgICAgICAvL2NvdXQ8PCJcbiAtLT5icmVhazogeCAiPDx4PDwiIHkgIjw8eTsKICAgICAgICAgICAgICAgICAgICAgIH0gCiAgICAgICAgICAgICAgICAgICAgICAKICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaWYoY291bnQ+PW51bUcpIHJlLnB1c2hfYmFjaygiWWVzIik7CiAgICAgICAgICAgIGVsc2UgcmUucHVzaF9iYWNrKCJObyIpOwogICAgICAgICAgICAKICAgICAgICB9CiAgICAgICAgCiAgICB9CiAgICAKICAgIGZvcihhdXRvIHM6cmUpewogICAgICAgIGNvdXQ8PHM8PCJcbiI7CiAgICB9CgogICAgcmV0dXJuIDA7Cn0=