#include <bits/stdc++.h>
using namespace std;
bool mat[55][55], vis[55][55];
bool valid(long long i, long long j, long long n, long long m) {
  return i >= 0 && i < n && j >= 0 && j < m;
}
long long mvx[] = {1, -1, 0, 0};
long long mvy[] = {0, 0, 1, -1};
void sh(long long i, long long j, long long n, long long m) {
  queue<pair<long long, long long> > q;
  vis[i][j] = 1;
  q.push(make_pair(i, j));
  while (!q.empty()) {
    auto f = (q.front());
    q.pop();
    vis[f.first][f.second] = 1;
    for (long long k = 0; k < 4; k++) {
      long long x = f.first + mvx[k];
      long long y = f.second + mvy[k];
      if (valid(x, y, n, m) && mat[x][y] != 1 && !vis[x][y]) {
        vis[x][y] = 1;
        q.push(make_pair(x, y));
      }
    }
  }
  return;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long t;
  cin >> t;
  while (t--) {
    long long n, m;
    cin >> n >> m;
    char temp[n][m];
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        cin >> temp[i][j];
      }
    }
    memset(vis, 0, sizeof(vis));
    memset(mat, 0, sizeof(mat));
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (temp[i][j] == 'B') {
          mat[i][j] = 1;
          for (long long k = 0; k < 4; k++) {
            long long x = i + mvx[k];
            long long y = j + mvy[k];
            if (valid(x, y, n, m)) {
              mat[x][y] = 1;
            }
          }
        }
      }
    }
    bool fg = true;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (temp[i][j] == 'G') {
          if (mat[i][j] == 1) {
            fg = false;
            break;
          }
          memset(vis, 0, sizeof(vis));
          sh(i, j, n, m);
          if (!vis[n - 1][m - 1]) {
            fg = false;
            break;
          }
        }
        if (!fg) break;
      }
      if (!fg) break;
    }
    if (fg)
      cout << "YES"
           << "\n";
    else
      cout << "NO"
           << "\n";
  }
}
