#include <map>
#include <set>
#include <vector>
#include <iostream>
using namespace std;
typedef long long ll;
typedef pair< int , int > pii;
const int MOD = 1e9 + 7 ;
const int MXN = 200005 ;
int dx[ ] = { - 1 , 0 , 1 } ;
bool withingRange( int x, int y, int N, int M) {
if ( ( x >= 0 && x < N) && ( y >= 0 && y < M) ) {
return true ;
}
return false ;
}
void demarcate( vector< string> & mat, int x, int y, int N, int M) {
for ( int i = 0 ; i < 3 ; i++ ) {
for ( int j = 0 ; j < 3 ; j++ ) {
if ( abs ( dx[ i] ) == abs ( dx[ j] ) ) {
continue ;
}
int newX = x + dx[ i] ;
int newY = y + dx[ j] ;
if ( withingRange( newX, newY, N, M) && mat[ newX] [ newY] == '.' ) {
mat[ newX] [ newY] = '#' ;
}
}
}
}
void demarcateAdjacentToB( vector< string> & mat, int N, int M) {
for ( int i = 0 ; i < N; i++ ) {
for ( int j = 0 ; j < M; j++ ) {
if ( mat[ i] [ j] == 'B' ) {
demarcate( mat, i, j, N, M) ;
}
}
}
}
bool check( vector< string> & mat, int x, int y, int N, int M) {
for ( int i = 0 ; i < 3 ; i++ ) {
for ( int j = 0 ; j < 3 ; j++ ) {
if ( abs ( dx[ i] ) == abs ( dx[ j] ) ) {
continue ;
}
int newX = x + dx[ i] ;
int newY = y + dx[ j] ;
if ( withingRange( newX, newY, N, M) ) {
if ( mat[ newX] [ newY] == 'G' ) {
return false ;
}
}
}
}
return true ;
}
bool checkAdjacent( vector< string> & mat, int N, int M) {
bool res = true ;
for ( int i = 0 ; i < N; i++ ) {
for ( int j = 0 ; j < M; j++ ) {
if ( mat[ i] [ j] == 'B' ) {
res = res & check( mat, i, j, N, M) ;
}
}
}
return res;
}
bool checkPath( vector< string> & mat, int x, int y, int N, int M) {
bool vis[ N] [ M] ;
vector< pii> myq;
for ( int i = 0 ; i < N; i++ ) {
for ( int j = 0 ; j < M; j++ ) {
vis[ i] [ j] = false ;
}
}
myq.push_back ( make_pair( x, y) ) ;
int siz = 1 ;
while ( siz > 0 ) {
pii cell = myq[ siz- 1 ] ;
x = cell.first ;
y = cell.second ;
vis[ x] [ y] = true ;
myq.pop_back ( ) ;
// cout<<"x: "<<x<<" y: "<<y<<endl;
siz-- ;
for ( int i = 0 ; i < 3 ; i++ ) {
for ( int j = 0 ; j < 3 ; j++ ) {
if ( abs ( dx[ i] ) == abs ( dx[ j] ) ) {
continue ;
}
// cout<<"dx: "<<dx[i]<<" dy: "<<dx[j]<<endl;
int newX = x + dx[ i] ;
int newY = y + dx[ j] ;
// cout<<"newX: "<<newX<<" newY: "<<newY<<endl;
if ( withingRange( newX, newY, N, M) && mat[ newX] [ newY] ! = '#' && ! vis[ newX] [ newY] ) {
myq.push_back ( make_pair( newX, newY) ) ;
siz++ ;
}
}
}
}
if ( vis[ N- 1 ] [ M- 1 ] ) {
return true ;
}
return false ;
}
void solve( ) {
int N, M;
vector< string> mat;
string s;
cin >> N >> M;
for ( int i = 0 ; i < N; i++ ) {
cin >> s;
mat.push_back ( s) ;
}
if ( ! checkAdjacent( mat, N, M) ) {
cout << "No" << endl;
return ;
}
demarcateAdjacentToB( mat, N, M) ;
bool res = true ;
for ( int i = 0 ; i < N; i++ ) {
for ( int j = 0 ; j < M; j++ ) {
if ( mat[ i] [ j] == 'G' ) {
// cout<<"i: "<<i<<" j: "<<j<<" "<<checkPath(mat, i, j, N, M)<<endl;
res = res & checkPath( mat, i, j, N, M) ;
}
}
}
if ( res) {
cout << "Yes" << endl;
} else {
cout << "No" << endl;
}
return ;
}
int main( ) {
int t;
cin >> t;
while ( t-- ) {
solve( ) ;
}
}
I2luY2x1ZGUgPG1hcD4KI2luY2x1ZGUgPHNldD4KI2luY2x1ZGUgPHZlY3Rvcj4KI2luY2x1ZGUgPGlvc3RyZWFtPgoKdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCnR5cGVkZWYgbG9uZyBsb25nIGxsOwp0eXBlZGVmIHBhaXI8aW50LCBpbnQ+cGlpOwoKY29uc3QgaW50IE1PRCA9IDFlOSArIDc7CmNvbnN0IGludCBNWE4gPSAyMDAwMDU7CgppbnQgZHhbXSA9IHstMSwgMCwgMX07Cgpib29sIHdpdGhpbmdSYW5nZShpbnQgeCwgaW50IHksIGludCBOLCBpbnQgTSkgewogICAgaWYoKHggPj0gMCAmJiB4IDwgTikgJiYgKHkgPj0gMCAmJiB5IDwgTSkpIHsKICAgICAgICByZXR1cm4gdHJ1ZTsKICAgIH0KICAgIHJldHVybiBmYWxzZTsKfQoKdm9pZCBkZW1hcmNhdGUodmVjdG9yPHN0cmluZz4gJm1hdCwgaW50IHgsIGludCB5LCBpbnQgTiwgaW50IE0pIHsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCAzOyBpKyspIHsKICAgICAgICBmb3IoaW50IGogPSAwOyBqIDwgMzsgaisrKSB7CiAgICAgICAgICAgIGlmKGFicyhkeFtpXSkgPT0gYWJzKGR4W2pdKSkgewogICAgICAgICAgICAgICAgY29udGludWU7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgaW50IG5ld1ggPSB4ICsgZHhbaV07CiAgICAgICAgICAgIGludCBuZXdZID0geSArIGR4W2pdOwoKICAgICAgICAgICAgaWYod2l0aGluZ1JhbmdlKG5ld1gsIG5ld1ksIE4sIE0pICYmIG1hdFtuZXdYXVtuZXdZXSA9PSAnLicpIHsKICAgICAgICAgICAgICAgIG1hdFtuZXdYXVtuZXdZXSA9ICcjJzsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KfQoKdm9pZCBkZW1hcmNhdGVBZGphY2VudFRvQih2ZWN0b3I8c3RyaW5nPiYgbWF0LCBpbnQgTiwgaW50IE0pIHsKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBOOyBpKyspIHsKICAgICAgICBmb3IoaW50IGogPSAwOyBqIDwgTTsgaisrKSB7CiAgICAgICAgICAgIGlmKG1hdFtpXVtqXSA9PSAnQicpIHsKICAgICAgICAgICAgICAgIGRlbWFyY2F0ZShtYXQsIGksIGosIE4sIE0pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQp9Cgpib29sIGNoZWNrKHZlY3RvcjxzdHJpbmc+JiBtYXQsIGludCB4LCBpbnQgeSwgaW50IE4sIGludCBNKSB7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgMzsgaSsrKSB7CiAgICAgICAgZm9yKGludCBqID0gMDsgaiA8IDM7IGorKykgewogICAgICAgICAgICBpZihhYnMoZHhbaV0pID09IGFicyhkeFtqXSkpIHsKICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGludCBuZXdYID0geCArIGR4W2ldOwogICAgICAgICAgICBpbnQgbmV3WSA9IHkgKyBkeFtqXTsKCiAgICAgICAgICAgIGlmKHdpdGhpbmdSYW5nZShuZXdYLCBuZXdZLCBOLCBNKSkgewogICAgICAgICAgICAgICAgaWYobWF0W25ld1hdW25ld1ldID09ICdHJykgewogICAgICAgICAgICAgICAgICAgIHJldHVybiBmYWxzZTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KICAgIHJldHVybiB0cnVlOwp9Cgpib29sIGNoZWNrQWRqYWNlbnQodmVjdG9yPHN0cmluZz4mIG1hdCwgaW50IE4sIGludCBNKSB7CiAgICBib29sIHJlcyA9IHRydWU7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgTjsgaSsrKSB7CiAgICAgICAgZm9yKGludCBqID0gMDsgaiA8IE07IGorKykgewogICAgICAgICAgICBpZihtYXRbaV1bal0gPT0gJ0InKSB7CiAgICAgICAgICAgICAgICByZXMgPSByZXMgJiBjaGVjayhtYXQsIGksIGosIE4sIE0pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQogICAgcmV0dXJuIHJlczsKfQoKYm9vbCBjaGVja1BhdGgodmVjdG9yPHN0cmluZz4mIG1hdCwgaW50IHgsIGludCB5LCBpbnQgTiwgaW50IE0pIHsKICAgIGJvb2wgdmlzW05dW01dOwogICAgdmVjdG9yPHBpaT4gbXlxOwoKICAgIGZvcihpbnQgaSA9IDA7IGkgPCBOOyBpKyspIHsKICAgICAgICBmb3IoaW50IGogPSAwOyBqIDwgTTsgaisrKSB7CiAgICAgICAgICAgIHZpc1tpXVtqXSA9IGZhbHNlOwogICAgICAgIH0KICAgIH0KCiAgICBteXEucHVzaF9iYWNrKG1ha2VfcGFpcih4LCB5KSk7CiAgICBpbnQgc2l6ID0gMTsKICAgIHdoaWxlKHNpeiA+IDApIHsKICAgICAgICBwaWkgY2VsbCA9IG15cVtzaXotMV07CiAgICAgICAgeCA9IGNlbGwuZmlyc3Q7CiAgICAgICAgeSA9IGNlbGwuc2Vjb25kOwogICAgICAgIHZpc1t4XVt5XSA9IHRydWU7CgogICAgICAgIG15cS5wb3BfYmFjaygpOwoKICAgICAgICAvLyBjb3V0PDwieDogIjw8eDw8IiB5OiAiPDx5PDxlbmRsOwogICAgICAgIHNpei0tOwoKICAgICAgICBmb3IoaW50IGkgPSAwOyBpIDwgMzsgaSsrKSB7CiAgICAgICAgICAgIGZvcihpbnQgaiA9IDA7IGogPCAzOyBqKyspIHsKICAgICAgICAgICAgICAgIGlmKGFicyhkeFtpXSkgPT0gYWJzKGR4W2pdKSkgewogICAgICAgICAgICAgICAgICAgIGNvbnRpbnVlOwogICAgICAgICAgICAgICAgfQoKICAgICAgICAgICAgICAgIC8vIGNvdXQ8PCJkeDogIjw8ZHhbaV08PCIgZHk6ICI8PGR4W2pdPDxlbmRsOwogICAgICAgICAgICAgICAgaW50IG5ld1ggPSB4ICsgZHhbaV07CiAgICAgICAgICAgICAgICBpbnQgbmV3WSA9IHkgKyBkeFtqXTsKCiAgICAgICAgICAgICAgICAvLyBjb3V0PDwibmV3WDogIjw8bmV3WDw8IiBuZXdZOiAiPDxuZXdZPDxlbmRsOwogICAgICAgICAgICAgICAgaWYod2l0aGluZ1JhbmdlKG5ld1gsIG5ld1ksIE4sIE0pICYmIG1hdFtuZXdYXVtuZXdZXSAhPSAnIycgJiYgIXZpc1tuZXdYXVtuZXdZXSkgewogICAgICAgICAgICAgICAgICAgIG15cS5wdXNoX2JhY2sobWFrZV9wYWlyKG5ld1gsIG5ld1kpKTsKICAgICAgICAgICAgICAgICAgICBzaXorKzsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQoKICAgICAgICB9CiAgICB9CiAgICBpZih2aXNbTi0xXVtNLTFdKSB7CiAgICAgICAgcmV0dXJuIHRydWU7CiAgICB9CiAgICByZXR1cm4gZmFsc2U7Cn0KCnZvaWQgc29sdmUoKSB7CiAgICBpbnQgTiwgTTsKICAgIHZlY3RvcjxzdHJpbmc+bWF0OwogICAgc3RyaW5nIHM7CgogICAgY2luPj5OID4+TTsKCiAgICBmb3IoaW50IGkgPSAwOyBpIDwgTjsgaSsrKSB7CiAgICAgICAgY2luPj5zOwogICAgICAgIG1hdC5wdXNoX2JhY2socyk7CiAgICB9CgogICAgaWYoIWNoZWNrQWRqYWNlbnQobWF0LCBOLCBNKSkgewogICAgICAgIGNvdXQ8PCJObyI8PGVuZGw7CiAgICAgICAgcmV0dXJuOwogICAgfQoKICAgIGRlbWFyY2F0ZUFkamFjZW50VG9CKG1hdCwgTiwgTSk7CgogICAgYm9vbCByZXMgPSB0cnVlOwogICAgZm9yKGludCBpID0gMDsgaSA8IE47IGkrKykgewogICAgICAgIGZvcihpbnQgaiA9IDA7IGogPCBNOyBqKyspIHsKICAgICAgICAgICAgaWYobWF0W2ldW2pdID09ICdHJykgewogICAgICAgICAgICAgICAgLy8gY291dDw8Imk6ICI8PGk8PCIgajogIjw8ajw8IiAiPDxjaGVja1BhdGgobWF0LCBpLCBqLCBOLCBNKTw8ZW5kbDsKICAgICAgICAgICAgICAgIHJlcyA9IHJlcyAmIGNoZWNrUGF0aChtYXQsIGksIGosIE4sIE0pOwogICAgICAgICAgICB9CiAgICAgICAgfQogICAgfQoKICAgIGlmKHJlcykgewogICAgICAgIGNvdXQ8PCJZZXMiPDxlbmRsOwogICAgfSBlbHNlIHsKICAgICAgICBjb3V0PDwiTm8iPDxlbmRsOwogICAgfQoKICAgIHJldHVybjsKCn0KCmludCBtYWluKCkgewogICAgaW50IHQ7CgogICAgY2luPj50OwoKICAgIHdoaWxlKHQtLSkgewogICAgICAgIHNvbHZlKCk7CiAgICB9Cn0K