#include <bits/stdc++.h>
using namespace std;
char g[60][60];
int n, m;
bool vis[60][60];
int dfs(int x, int y) {
  if (x > n || y > m || x < 1 || y < 1 || vis[x][y]) return 0;
  vis[x][y] = true;
  if (g[x][y] == '#') return 0;
  return dfs(x - 1, y) + dfs(x + 1, y) + dfs(x, y - 1) + dfs(x, y + 1) +
         (g[x][y] == 'G');
}
void draw(int x, int y) {
  if (x > n || y > m || x < 1 || y < 1) return;
  g[x][y] = '#';
}
int main() {
  ios::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    int cnt1 = 0;
    for (int i = 1; i <= n; ++i) {
      for (int j = 1; j <= m; ++j) {
        cin >> g[i][j];
        if (g[i][j] == 'G') ++cnt1;
        vis[i][j] = false;
      }
    }
    if (cnt1 != dfs(n, m))
      cout << "NO\n";
    else {
      for (int i = 1; i <= n; ++i) {
        for (int j = 1; j <= m; ++j) {
          if (g[i][j] == 'B') {
            draw(i, j);
            draw(i - 1, j);
            draw(i + 1, j);
            draw(i, j - 1);
            draw(i, j + 1);
          }
          vis[i][j] = false;
        }
      }
      if (dfs(n, m) == cnt1)
        cout << "YES\n";
      else
        cout << "NO\n";
    }
  }
}
