#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,numB;
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+CiNkZWZpbmUgcGkgcGFpcjxpbnQsIGludD4KI2RlZmluZSB4IGZpcnN0CiNkZWZpbmUgeSBzZWNvbmQKCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CgppbnQgbWFpbigpCnsKICAgIGludCB0OwogICAgY2luPj50OwogICAgc3RkOjp2ZWN0b3I8c3RyaW5nPiByZTsKICAgIGZvcihpbnQgaT0wO2k8dDtpKyspewogICAgICAgIGludCBuLG07CiAgICAgICAgY2luPj5uPj5tOwogICAgICAgIGNoYXIgYXJbbl1bbV07CiAgICAgICAgYm9vbCB2W25dW21dOwogICAgICAgIGludCBudW1HLG51bUI7CiAgICAgICAgCiAgICAgICAgZm9yKGludCBqPTA7ajxuO2orKyl7CiAgICAgICAgICBmb3IoaW50IGs9MDtrPG07aysrKXsKICAgICAgICAgICAgICB2W2pdW2tdID0gZmFsc2U7CiAgICAgICAgICAgICAgY2luPj5hcltqXVtrXTsKICAgICAgICAgICAgICBpZihhcltqXVtrXT09J0cnKSBudW1HKys7CiAgICAgICAgICAgICAgZWxzZSBpZihhcltqXVtrXT09J0InKSBudW1CKys7CiAgICAgICAgICAgICAgZWxzZSBpZihhcltqXVtrXT09JyMnKSAgdltqXVtrXSA9IHRydWU7CiAgICAgICAgICAgICAgCiAgICAgICAgICB9ICAKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgY291dDw8IlxuLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS0tLS1cbiI7CiAgICAgICAgZm9yKGludCBqPTA7ajxuO2orKyl7CiAgICAgICAgICAgIGNvdXQ8PCJcbiI7CiAgICAgICAgICBmb3IoaW50IGs9MDtrPG07aysrKXsKICAgICAgICAgICAgIGNvdXQ8PCIgIjw8YXJbal1ba107CiAgICAgICAgICAgICAgCiAgICAgICAgICB9ICAKICAgICAgICB9CiAgICAgICAgCiAgICAgICAgYm9vbCBuZWVkQnJlYWsgPSBmYWxzZTsKICAgICAgICBpZihudW1HPT0wKSB7CiAgICAgICAgICAgIHJlLnB1c2hfYmFjaygiWWVzIik7CiAgICAgICAgICAgIG5lZWRCcmVhayA9IHRydWU7CiAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgIH0KICAgICAgICAKICAgICAgICBpbnQgZHhbXSA9IHswLDAsMSwtMX07CiAgICAgICAgaW50IGR5W10gPSB7MSwtMSwwLDB9OwogICAgICAgIAogICAgICAgIAogICAgICAgIAogICAgICAgIGZvcihpbnQgaj0wO2o8bjtqKyspewogICAgICAgICAgZm9yKGludCBrPTA7azxtO2srKyl7CiAgICAgICAgICAgICAgaWYoYXJbal1ba109PSdCJyl7CiAgICAgICAgICAgICAgICAgIGlmKG5lZWRCcmVhaykgYnJlYWs7CiAgICAgICAgICAgICAgICAgIHZbal1ba10gPSB0cnVlOwogICAgICAgICAgICAgICAgICBmb3IoaW50IGg9MDtoPDQ7aCsrKXsKICAgICAgICAgICAgICAgICAgICAgIC8vY291dDw8IlxuIGogIjw8ajw8IiBrICI8PGsgPDwiIGggIjw8aDsKICAgICAgICAgICAgICAgICAgICAgIGludCB4ID0gaitkeFtoXTsKICAgICAgICAgICAgICAgICAgICAgIGludCB5ID0gaytkeVtoXTsKICAgICAgICAgICAgICAgICAgICAgIGlmKHg8MCB8fCB5PDB8fHg+PW58fHk+PW0pIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgICAgICAgLy9jb3V0PDwiXG4gLS0+IHggIjw8eDw8IiB5ICI8PHk7CiAgICAgICAgICAgICAgICAgICAgICBpZihhclt4XVt5XT09J0cnKSB7CiAgICAgICAgICAgICAgICAgICAgICAgICAgbmVlZEJyZWFrID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgICAgICByZS5wdXNoX2JhY2soIk5vIik7CiAgICAgICAgICAgICAgICAgICAgICAgICAgLy9jb3V0PDwiXG4gLS0+YnJlYWs6IHggIjw8eDw8IiB5ICI8PHk7CiAgICAgICAgICAgICAgICAgICAgICAgICAgYnJlYWs7CiAgICAgICAgICAgICAgICAgICAgICB9IGVsc2UgaWYoYXJbeF1beV09PScuJykgewogICAgICAgICAgICAgICAgICAgICAgICAgIGFyW3hdW3ldPScjJzsKICAgICAgICAgICAgICAgICAgICAgICAgICB2W3hdW3ldID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgIH0KICAgICAgICAgIH0gIAogICAgICAgIH0KICAgICAgICAKICAgICAgICBpZihuZWVkQnJlYWspIGNvbnRpbnVlOwogICAgICAgIGVsc2UgewogICAgICAgICAgICBpZihhcltuLTFdW20tMV09PScjJyl7CiAgICAgICAgICAgICAgICByZS5wdXNoX2JhY2soIk5vIik7CiAgICAgICAgICAgICAgICBjb250aW51ZTsKICAgICAgICAgICAgfQogICAgICAgICAgICBpbnQgY291bnQgPSAwOwogICAgICAgICAgICBzdGQ6OnF1ZXVlPHBpPiBxIDsKICAgICAgICAgICAgcS5wdXNoKHtuLTEsIG0tMX0pOwogICAgICAgICAgICB2W24tMV1bbS0xXSA9IHRydWU7CiAgICAgICAgICAgIHdoaWxlKCFxLmVtcHR5KCkpewogICAgICAgICAgICAgICAgcGkgdG9wID0gcS5mcm9udCgpOwogICAgICAgICAgICAgICAgcS5wb3AoKTsKICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgZm9yKGludCBoPTA7aDw0O2grKyl7CiAgICAgICAgICAgICAgICAgICAgICAvL2NvdXQ8PCJcbiBqICI8PGo8PCIgayAiPDxrIDw8IiBoICI8PGg7CiAgICAgICAgICAgICAgICAgICAgICBpbnQgeCA9IHRvcC54K2R4W2hdOwogICAgICAgICAgICAgICAgICAgICAgaW50IHkgPSB0b3AueStkeVtoXTsKICAgICAgICAgICAgICAgICAgICAgIGlmKHg8MCB8fCB5PDB8fHg+PW58fHk+PW0gfHwgdlt4XVt5XSkgY29udGludWU7CiAgICAgICAgICAgICAgICAgICAgICAvL2NvdXQ8PCJcbiAtLT4geCAiPDx4PDwiIHkgIjw8eTsKICAgICAgICAgICAgICAgICAgICAgIHEucHVzaCh7eCx5fSk7CiAgICAgICAgICAgICAgICAgICAgICB2W3hdW3ldID0gdHJ1ZTsKICAgICAgICAgICAgICAgICAgICAgIGlmKGFyW3hdW3ldPT0nRycpIHsKICAgICAgICAgICAgICAgICAgICAgICAgICBjb3VudCsrOwogICAgICAgICAgICAgICAgICAgICAgICAgIC8vY291dDw8IlxuIC0tPmJyZWFrOiB4ICI8PHg8PCIgeSAiPDx5OwogICAgICAgICAgICAgICAgICAgICAgfSAKICAgICAgICAgICAgICAgICAgICAgIAogICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgICAgICBpZihjb3VudD49bnVtRykgcmUucHVzaF9iYWNrKCJZZXMiKTsKICAgICAgICAgICAgZWxzZSByZS5wdXNoX2JhY2soIk5vIik7CiAgICAgICAgICAgIAogICAgICAgIH0KICAgICAgICAKICAgIH0KICAgIAogICAgZm9yKGF1dG8gczpyZSl7CiAgICAgICAgY291dDw8czw8IlxuIjsKICAgIH0KCiAgICByZXR1cm4gMDsKfQ==