#include <bits/stdc++.h>
using namespace std;
int T;
int n, m, vis[52][52];
char c[52][52];
template <typename Tp>
void read(Tp &x) {
  x = 0;
  int f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  x *= f;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
void dfs(int x, int y) {
  if (c[x][y] == '#') return;
  vis[x][y] = 1;
  for (int k = 0; k < 4; k++) {
    int xx = x + dx[k], yy = y + dy[k];
    if (xx < 1 || xx > n || yy < 1 || yy > m) continue;
    if (!vis[xx][yy]) dfs(xx, yy);
  }
}
int main() {
  read(T);
  while (T--) {
    read(n), read(m);
    for (int i = 1; i <= n; i++) scanf("%s", c[i] + 1);
    bool flag = true;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (c[i][j] == 'B') {
          for (int k = 0; k < 4; k++) {
            int xx = i + dx[k], yy = j + dy[k];
            if (xx < 1 || xx > n || yy < 1 || yy > m) continue;
            if (c[xx][yy] == 'G') {
              flag = false;
              break;
            } else if (c[xx][yy] == '.')
              c[xx][yy] = '#';
          }
        }
        if (!flag) break;
      }
      if (!flag) break;
    }
    if (!flag)
      printf("NO\n");
    else {
      dfs(n, m);
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) {
          if (c[i][j] == 'G' && !vis[i][j]) {
            flag = false;
            break;
          }
        }
        if (!flag) break;
      }
      if (!flag)
        printf("NO\n");
      else
        printf("YES\n");
    }
    memset(vis, 0, sizeof(vis));
  }
  return 0;
}
