#include <bits/stdc++.h>
using namespace std;
long long x[4] = {1, -1, 0, 0};
long long y[4] = {0, 0, 1, -1};
bool vis[55][55];
char a[55][55];
long long n, m;
bool bfs(long long p, long long s) {
  memset(vis, false, sizeof(vis));
  queue<pair<long long, long long> > q;
  if (a[p][s] == '.') {
    vis[p][s] = true;
    q.push(make_pair(p, s));
  }
  while (!q.empty()) {
    pair<long long, long long> u = q.front();
    q.pop();
    for (long long i = 0; i < 4; i++) {
      long long vx = u.first + x[i];
      long long vy = u.second + x[i];
      if ((vx >= 0 && vx <= p) && (vy >= 0 && vy <= s) && a[vx][vy] != '#' &&
          !vis[vx][vy]) {
        q.push(make_pair(vx, vy));
        vis[vx][vy] = true;
      }
    }
  }
  bool good = true;
  for (long long i = 0; i <= p; i++) {
    for (long long j = 0; j <= s; j++) {
      if ((a[i][j] == 'G' && !vis[i][j]) || (a[i][j] == 'B' && vis[i][j])) {
        good = false;
        break;
      }
    }
  }
  return good;
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        cin >> a[i][j];
      }
    }
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (a[i][j] == 'B') {
          for (long long k = 0; k < 4; k++) {
            long long dx = i + x[k];
            long long dy = j + y[k];
            if ((dx >= 0 && dx < n) && (dy >= 0 && dy < m) && a[dx][dy] == '.')
              a[dx][dy] = '#';
          }
        }
      }
    }
    bool mdd = bfs(n - 1, m - 1);
    if (mdd)
      cout << "YES" << endl;
    else
      cout << "No" << endl;
  }
}
