#include <bits/stdc++.h>
using namespace std;
template <typename T>
ostream &operator<<(ostream &o, vector<T> v) {
  if (v.size() > 0) o << v[0];
  for (unsigned i = 1; i < v.size(); i++) o << " " << v[i];
  return o << endl;
}
bool sortbysec(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.first - a.second) > (b.first - b.second);
}
int n, m;
int vis[51][51];
std::vector<string> v;
vector<pair<int, int>> q;
int isvalid(int i, int j) {
  if (i < 0 || j < 0) return -1;
  if (i >= n || j >= m) return -1;
  if (v[i][j] == '#') return -1;
  if (v[i][j] == 'B') return 0;
  if (v[i][j] == 'G') return 1;
  return 2;
}
bool flag;
int bfs(int i, int j) {
  int cnt = 0;
  queue<pair<int, int>> qt;
  qt.push({i, j});
  while (!qt.empty()) {
    int x = qt.front().first;
    int y = qt.front().second;
    qt.pop();
    if (vis[x][y]) continue;
    vis[x][y] = 1;
    if (v[x][y] == 'G') cnt++;
    if (isvalid(x - 1, y) != -1) qt.push({x - 1, y});
    if (isvalid(x + 1, y) != -1) qt.push({x + 1, y});
    if (isvalid(x, y - 1) != -1) qt.push({x, y - 1});
    if (isvalid(x, y + 1) != -1) qt.push({x, y + 1});
  }
  return cnt;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    v.clear();
    cin >> n >> m;
    memset(vis, 0, sizeof(vis));
    int cnt1 = 0, cnt2 = 0;
    for (int i = 0; i < n; ++i) {
      string s;
      cin >> s;
      v.push_back(s);
      for (int j = 0; j < m; j++) {
        if (v[i][j] == 'G') {
          cnt1++;
        }
        if (v[i][j] == 'B') cnt2++;
      }
    }
    if (cnt1 == 0) {
      cout << "Yes" << endl;
      continue;
    }
    flag = true;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (v[i][j] == 'B') {
          if (isvalid(i, j - 1) == 2)
            v[i][j - 1] = '#';
          else if (isvalid(i, j - 1) == 1)
            flag = false;
          if (isvalid(i, j + 1) == 2)
            v[i][j + 1] = '#';
          else if (isvalid(i, j + 1) == 1)
            flag = false;
          if (isvalid(i + 1, j) == 2)
            v[i + 1][j] = '#';
          else if (isvalid(i + 1, j) == 1)
            flag = false;
        }
      }
    }
    if (v[n - 1][m - 1] == '#') flag = false;
    int cnt = bfs(n - 1, m - 1);
    if (cnt != cnt1) flag = false;
    if (flag)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
  return 0;
}
