#include <bits/stdc++.h>
using namespace std;
int T, n, m, a[60][60], vis[60][60];
vector<pair<int, int> > v, b;
char s[60][60];
const int dx[4] = {0, 1, 0, -1};
const int dy[4] = {1, 0, -1, 0};
void bfs(int x, int y) {
  vis[x][y] = 1;
  for (int i = 0; i < 4; ++i) {
    int nx = x + dx[i], ny = y + dy[i];
    if (vis[nx][ny] || nx < 1 || ny < 1 || nx > n || ny > m || a[nx][ny] == 1)
      continue;
    bfs(nx, ny);
  }
}
int main() {
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d", &n, &m);
    v.clear(), b.clear();
    for (int i = 1; i <= 50; ++i)
      for (int j = 1; j <= 50; ++j) vis[i][j] = a[i][j] = 0;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        cin >> s[i][j];
        if (s[i][j] == 'G') v.push_back(make_pair(i, j)), a[i][j] = 2;
        if (s[i][j] == 'B') b.push_back(make_pair(i, j)), a[i][j] = 3;
        if (s[i][j] == '#') a[i][j] = 1;
        if (s[i][j] == '.') a[i][j] = 0;
      }
    }
    if (!v.size()) {
      puts("YES");
      continue;
    }
    int fg = 0;
    for (int i = 0; i < (int)b.size() && !fg; ++i) {
      int x = b[i].first, y = b[i].second;
      for (int j = 0; j < 4; ++j) {
        int nx = x + dx[j], ny = y + dy[j];
        if (a[nx][ny] == 2) {
          fg = 1;
          puts("NO");
          break;
        }
        if (a[nx][ny] == 3) continue;
        a[nx][ny] = 1;
      }
    }
    if (fg) continue;
    if (a[n][m]) {
      puts("NO");
      continue;
    }
    bfs(n, m);
    for (int i = 0; i < (int)v.size(); ++i) {
      if (!vis[v[i].first][v[i].second]) {
        puts("NO");
        fg = 1;
        break;
      }
    }
    if (!fg) puts("YES");
  }
  return 0;
}
