#include <bits/stdc++.h>
using namespace std;
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }
  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM =
        chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};
const int N = 2e5 + 1;
const int M = N;
const int mod = 998244353;
long long int a[N], b[N], c[N];
void solve() {
  int n, m;
  cin >> n >> m;
  string s[51];
  for (int i = 0; i < n; ++i) {
    cin >> s[i];
  }
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (s[i][j] == 'B') {
        if (i > 0) {
          if (s[i - 1][j] == '.') {
            s[i - 1][j] = '#';
          } else if (s[i - 1][j] == 'G') {
            cout << "NO" << endl;
            return;
          }
        }
        if (j > 0) {
          if (s[i][j - 1] == '.') {
            s[i][j - 1] = '#';
          } else if (s[i][j - 1] == 'G') {
            cout << "NO" << endl;
            return;
          }
        }
        if (i < n - 1) {
          if (s[i + 1][j] == '.') {
            s[i + 1][j] = '#';
          } else if (s[i + 1][j] == 'G') {
            cout << "NO" << endl;
            return;
          }
        }
        if (j < m - 1) {
          if (s[i][j + 1] == '.') {
            s[i][j + 1] = '#';
          } else if (s[i][j + 1] == 'G') {
            cout << "NO" << endl;
            return;
          }
        }
      }
    }
  }
  int dp[51][51];
  memset(dp, 0, sizeof(dp));
  bool yes = true;
  for (int i = n; i--;) {
    for (int j = m; j--;) {
      if (i == n - 1 && j == m - 1 && s[i][j] == '.') {
        dp[i][j] = 1;
        continue;
      }
      if (s[i][j] == '.' || s[i][j] == 'G') {
        dp[i][j] = (i > 0 ? dp[i - 1][j] : 0) ||
                   (i + 1 < n ? dp[i + 1][j] : 0) ||
                   (j > 0 ? dp[i][j - 1] : 0) || (j + 1 < m ? dp[i][j + 1] : 0);
      }
      if (s[i][j] == 'G') {
        yes &= dp[i][j];
      }
    }
  }
  yes ? cout << "YES" << endl : cout << "NO" << endl;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
