#include <bits/stdc++.h>
int n, m;
using namespace std;
int visi[51][51];
int wall[51][51];
void dfs(int i, int j) {
  if (visi[i][j] == 1 || wall[i][j] == 1) {
    return;
  }
  visi[i][j] = 1;
  if (i < n - 1) dfs(i + 1, j);
  if (j < m - 1) dfs(i, j + 1);
  if (i > 0) dfs(i - 1, j);
  if (j > 0) dfs(i, j - 1);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    char c[51][51];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> c[i][j];
      }
    }
    memset(visi, 0, sizeof(visi));
    memset(wall, 0, sizeof(wall));
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (wall[i][j] == 0 && (c[i][j] == '#' || c[i][j] == 'B')) {
          wall[i][j] = 1;
        }
        if (c[i][j] == 'B') {
          if (i < n - 1) wall[i + 1][j] = 1;
          if (j < m - 1) wall[i][j + 1] = 1;
          if (i > 0) wall[i - 1][j] = 1;
          if (j > 0) wall[i][j - 1] = 1;
        }
      }
    }
    int ok = 1;
    dfs(n - 1, m - 1);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (c[i][j] == 'G' && visi[i][j] != 1) {
          ok = 0;
          break;
        }
      }
      if (ok == 0) break;
    }
    if (ok == 1)
      cout << "YES" << endl;
    else {
      cout << "NO" << endl;
    }
  }
}
