#include <bits/stdc++.h>
using namespace std;
long long dx[] = {1, 0, -1, 0};
long long dy[] = {0, 1, 0, -1};
int32_t main() {
  ios::sync_with_stdio(0), cin.tie(0);
  long long T;
  cin >> T;
  while (T--) {
    long long n, m, cnt = 0;
    cin >> n >> m;
    string st[n];
    for (long long i = 0; i < n; i++) cin >> st[i];
    long long ok = 1;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (st[i][j] == 'G') cnt++;
        if (st[i][j] == 'B') {
          for (long long k = 0; k < 4; k++) {
            long long x = i + dx[k], y = j + dy[k];
            if (x < 0 or x >= n or y < 0 or y >= m) continue;
            if (st[x][y] == '.') st[x][y] = '#';
            if (st[x][y] == 'G') ok = 0;
          }
        }
      }
    }
    if (!ok) {
      cout << "No\n";
      continue;
    }
    queue<pair<long long, long long> > q;
    long long vis[n][m];
    memset(vis, 0, sizeof vis);
    if (st[n - 1][m - 1] == '.') q.push({n - 1, m - 1}), vis[n - 1][m - 1] = 1;
    while (!q.empty()) {
      auto [i, j] = q.front();
      q.pop();
      if (st[i][j] == 'G') cnt--;
      for (long long k = 0; k < 4; k++) {
        long long x = i + dx[k], y = j + dy[k];
        if (x < 0 or x >= n or y < 0 or y >= m or vis[x][y]) continue;
        if (st[x][y] == 'G' or st[x][y] == '.') q.push({x, y});
        vis[x][y] = 1;
      }
    }
    if (!ok or cnt > 0) {
      cout << "No\n";
      continue;
    }
    cout << "Yes\n";
  }
}
