#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
mt19937 mrand(random_device{}());
const long long mod = 1000000007;
int rnd(int x) { return mrand() % x; }
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
int dirx[] = {0, 0, 1, -1};
int diry[] = {1, -1, 0, 0};
int n, m;
bool valid(int x, int y) { return ((x >= 1 && x <= n) && (y >= 1 && y <= m)); }
void dfs(bool visited[][55], int x, int y, char a[][55]) {
  visited[x][y] = true;
  for (int i = 0; i < 3; i++) {
    int xt = x + dirx[i];
    int yt = y + diry[i];
    if (valid(xt, yt) && a[xt][yt] != '#' && visited[xt][yt] == false)
      dfs(visited, xt, yt, a);
  }
}
void solve() {
  cin >> n >> m;
  char a[55][55];
  for (int i = 1; i < n + 1; i++) {
    cin >> (a[i] + 1);
  }
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      if (a[i][j] == 'B') {
        for (int k = 0; k < 4; k++) {
          int x = i + dirx[k];
          int y = j + diry[k];
          if (valid(x, y) && a[x][y] == '.') a[x][y] = '#';
        }
      }
    }
  }
  bool visited[55][55];
  memset(visited, false, sizeof(visited));
  if (a[n][m] == '.') dfs(visited, n, m, a);
  for (int i = 1; i < n + 1; i++) {
    for (int j = 1; j < m + 1; j++) {
      if (a[i][j] == 'G' && visited[i][j] == false) {
        cout << "NO" << endl;
        return;
      }
      if (a[i][j] == 'B' && visited[i][j] == true) {
        cout << "NO" << endl;
        return;
      }
    }
  }
  cout << "YES" << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
