#include <bits/stdc++.h>
using namespace std;
bool solve() {
  int N, M;
  cin >> N >> M;
  string S[50];
  for (int i = 0; i < N; i++) cin >> S[i];
  bitset<50> blocked[50];
  auto inside = [&](int i, int j) {
    return i >= 0 && i < N && j >= 0 && j < M && !blocked[i][j];
  };
  int dx[] = {-1, 1, 0, 0};
  int dy[] = {0, 0, -1, 1};
  vector<pair<int, int>> good;
  for (int i = 0; i < N; i++)
    for (int j = 0; j < M; j++) {
      if (S[i][j] == '#') blocked[i][j] = 1;
      if (S[i][j] == 'G') good.emplace_back(i, j);
      if (S[i][j] == 'B') {
        blocked[i][j] = 1;
        for (int k = 0; k < 4; k++) {
          int x = i + dx[k], y = j + dy[k];
          if (inside(x, y)) blocked[x][y] = 1;
        }
      }
    }
  if (good.size() == 0 && S[N - 1][M - 1] != 'B') return true;
  if (blocked[N - 1][M - 1]) return false;
  bitset<50> reachable[50];
  reachable[N - 1][M - 1] = 1;
  queue<pair<int, int>> que;
  que.emplace(N - 1, M - 1);
  while (que.size()) {
    auto [i, j] = que.front();
    que.pop();
    for (int k = 0; k < 4; k++) {
      int x = i + dx[k], y = j + dy[k];
      if (inside(x, y) && !reachable[x][y]) {
        reachable[x][y] = 1;
        que.emplace(x, y);
      }
    }
  }
  for (auto [i, j] : good)
    if (!reachable[i][j]) return false;
  return true;
}
int main() {
  int T;
  cin >> T;
  while (T--) cout << (solve() ? "Yes" : "No") << endl;
  return 0;
}
