#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
const int inf = 0x3f3f3f3f;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int n, m, resB, resG, sumG, sumB;
string s[60];
int to[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
bool vis[60][60];
bool check(int i, int j) { return i >= 0 && i < n && j >= 0 && j < m; }
queue<pair<int, int> > q;
void bfs_wall() {
  memset(vis, 0, sizeof(vis));
  while (!q.empty()) q.pop();
  ;
  q.push(make_pair(n - 1, m - 1));
  while (!q.empty()) {
    int x = (q.front()).first, y = (q.front()).second;
    vis[x][y] = 1;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int xx = x + to[i][0], yy = y + to[i][1];
      if (!check(xx, yy)) continue;
      if (s[xx][yy] == '.' || s[xx][yy] == 'G') {
        if (!vis[xx][yy]) q.push(make_pair(xx, yy));
        vis[xx][yy] = 1;
      } else if (s[xx][yy] == 'B') {
        s[x][y] = '#';
      }
    }
  }
}
int bfs_find() {
  memset(vis, 0, sizeof(vis));
  resB = resG = 0;
  while (!q.empty()) q.pop();
  ;
  if (s[n - 1][m - 1] == '.') q.push(make_pair(n - 1, m - 1));
  while (!q.empty()) {
    int x = (q.front()).first, y = (q.front()).second;
    vis[x][y] = 1;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int xx = x + to[i][0], yy = y + to[i][1];
      if (!check(xx, yy)) continue;
      if (s[xx][yy] == '.' && !vis[xx][yy]) {
        q.push(make_pair(xx, yy));
        vis[xx][yy] = 1;
      } else if (s[xx][yy] == 'B') {
        return 0;
      } else if (s[xx][yy] == 'G' && !vis[xx][yy]) {
        q.push(make_pair(xx, yy));
        vis[xx][yy] = 1;
        resG++;
      }
    }
  }
  return 1;
}
int main() {
  int t = read();
  while (t--) {
    n = read(), m = read();
    sumG = 0;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      for (int j = 0; j < m; j++) {
        if (s[i][j] == 'G') sumG++;
      }
    }
    bfs_wall();
    if (bfs_find() && resG == sumG)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
