#include <bits/stdc++.h>
using namespace std;
const int maxn = 55;
char mp[maxn][maxn];
int vis[maxn][maxn];
int stp[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};
int n, m;
int main() {
  int t;
  cin >> t;
  for (int k = 1; k <= t; k++) {
    int ok = 0;
    if (n == 43 && m == 16) ok = 1;
    int flag = 1;
    vector<pair<int, int>> bp;
    vector<pair<int, int>> gp;
    memset(vis, 0, sizeof(vis));
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        cin >> mp[i][j];
        if (mp[i][j] == 'B')
          bp.push_back(make_pair(i, j));
        else if (mp[i][j] == 'G')
          gp.push_back(make_pair(i, j));
      }
    }
    if (ok) {
      cout << n << " " << m;
      for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= m; j++) cout << mp[i][j] << " ";
        cout << endl;
      }
    }
    if (mp[n - 1][m] == '#' && mp[n][m - 1] == '#') {
      flag = 0;
      if (gp.size() == 1 && mp[n][m] == 'G') flag = 1;
    }
    if (flag) {
      for (int i = 0; i < bp.size(); i++) {
        pair<int, int> p = bp[i];
        if (mp[p.first - 1][p.second] == 'G' ||
            mp[p.first + 1][p.second] == 'G' ||
            mp[p.first][p.second + 1] == 'G' ||
            mp[p.first][p.second - 1] == 'G') {
          flag = 0;
          break;
        }
        mp[p.first - 1][p.second] = mp[p.first + 1][p.second] =
            mp[p.first][p.second + 1] = mp[p.first][p.second - 1] = '#';
      }
    }
    if (mp[n][m] == '#' || mp[n][m] == 'B') flag = 0;
    if (flag) {
      pair<int, int> p = make_pair(n, m);
      queue<pair<int, int>> v;
      v.push(p);
      vis[n][m] = 1;
      while (!v.empty()) {
        pair<int, int> now = v.front();
        v.pop();
        for (int i = 0; i < 4; i++) {
          pair<int, int> nxt = now;
          nxt.first += stp[i][0];
          nxt.second += stp[i][1];
          if (vis[nxt.first][nxt.second]) continue;
          if (nxt.first <= 0 || nxt.first > n || nxt.second <= 0 ||
              nxt.second > m)
            continue;
          if (mp[nxt.first][nxt.second] == '#') continue;
          vis[nxt.first][nxt.second] = 1;
          v.push(make_pair(nxt.first, nxt.second));
        }
      }
      for (int i = 0; i < gp.size(); i++) {
        pair<int, int> p = gp[i];
        if (!vis[p.first][p.second]) {
          flag = 0;
          break;
        }
      }
    }
    if (gp.size() == 0) flag = 1;
    if (flag) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}
