#include <bits/stdc++.h>
using namespace std;
vector<string> v;
long long n, m;
bool chk(long long i, long long j) {
  return i >= 0 && i < n && j >= 0 && j < m;
}
long long xd[4] = {1, 0, -1, 0};
long long yd[4] = {0, 1, 0, -1};
long long zz = 0;
bool vis[51][51];
void dfs(long long i, long long j) {
  if (vis[i][j]) return;
  vis[i][j] = 1;
  if (i == n - 1 && j == m - 1) zz = 1;
  for (long long u = 0; u < 4; u = u + 1) {
    long long xx = i + xd[u], yy = j + yd[u];
    if (chk(xx, yy))
      if (v[xx][yy] != '#') {
        dfs(xx, yy);
      }
  }
  vis[i][j] = 0;
}
void cd(long long i, long long j) {
  if (vis[i][j]) return;
  vis[i][j] = 1;
  for (long long u = 0; u < 4; u = u + 1) {
    long long xx = i + xd[u], yy = j + yd[u];
    if (chk(xx, yy))
      if (v[xx][yy] != '#') {
        if (v[xx][yy] == '.') {
          v[xx][yy] = '#';
        } else
          cd(xx, yy);
      }
  }
  vis[i][j] = 0;
}
void cdd(long long i, long long j) {
  if (vis[i][j]) return;
  vis[i][j] = 1;
  v[i][j] = 'b';
  for (long long u = 0; u < 4; u = u + 1) {
    long long xx = i + xd[u], yy = j + yd[u];
    if (chk(xx, yy))
      if (v[xx][yy] == 'B') {
        cdd(xx, yy);
      }
  }
  vis[i][j] = 0;
}
void cg(long long i, long long j) {
  if (vis[i][j]) return;
  vis[i][j] = 1;
  v[i][j] = 'g';
  for (long long u = 0; u < 4; u = u + 1) {
    long long xx = i + xd[u], yy = j + yd[u];
    if (chk(xx, yy))
      if (v[xx][yy] == 'G') {
        cg(xx, yy);
      }
  }
  vis[i][j] = 0;
}
long long xg = 0;
void go(long long i, long long j) {
  if (vis[i][j]) return;
  vis[i][j] = 1;
  if (v[i][j] == 'G') xg++;
  for (long long u = 0; u < 4; u = u + 1) {
    long long xx = i + xd[u], yy = j + yd[u];
    if (chk(xx, yy))
      if (v[xx][yy] != '#') {
        go(xx, yy);
      }
  }
  vis[i][j] = 0;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long t;
  cin >> t;
  while (t--) {
    memset(vis, 0, sizeof(vis));
    v.clear();
    xg = 0;
    cin >> n >> m;
    for (long long i = 0; i < n; i = i + 1) {
      string w;
      cin >> w;
      v.push_back(w);
    }
    long long zg = 0;
    for (long long i = 0; i < n; i = i + 1)
      for (long long j = 0; j < m; j = j + 1) zg += (v[i][j] == 'G');
    for (long long i = 0; i < n; i = i + 1) {
      for (long long j = 0; j < m; j = j + 1) {
        if (v[i][j] == 'B') {
          dfs(i, j);
          bool p = zz;
          zz = 0;
          if (p) {
            cd(i, j);
          }
          cdd(i, j);
        }
      }
    }
    memset(vis, 0, sizeof(vis));
    if (v[n - 1][m - 1] != '#') go(n - 1, m - 1);
    long long z = xg;
    if (zg == z)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}
