#include <bits/stdc++.h>
using namespace std;
const int sz = 2e5 + 5;
vector<int> ar[sz];
int pr[sz];
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, -1, 1};
int n, m;
bool check(int x, int y) { return x >= 0 and x < n and y >= 0 and y < m; }
pair<int, int> par[55][55];
pair<int, int> root(int i, int j) {
  while (par[i][j] != make_pair(i, j)) {
    par[i][j] = par[par[i][j].first][par[i][j].second];
    i = par[i][j].first;
    j = par[i][j].second;
  }
  return {i, j};
}
void uni(int x, int y, int nx, int ny) {
  pair<int, int> ra = root(x, y);
  pair<int, int> rb = root(nx, ny);
  if (ra == rb) return;
  par[ra.first][ra.second] = rb;
}
int main() {
  int t = 1;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    char ch[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> ch[i][j];
        par[i][j] = {i, j};
      }
    }
    string ans = "Yes";
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (ch[i][j] == 'B') {
          for (int k = 0; k < 4; k++) {
            int nx = i + dx[k];
            int ny = j + dy[k];
            if (check(nx, ny) == false) continue;
            if (ch[nx][ny] == 'G') {
              ans = "No";
            } else {
              ch[nx][ny] = '#';
            }
          }
        }
      }
    }
    int cnt = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (ch[i][j] == 'G') {
          cnt++;
          for (int k = 0; k < 4; k++) {
            int nx = i + dx[k];
            int ny = j + dy[k];
            if (check(nx, ny) == false) continue;
            if (ch[nx][ny] == '.' or ch[nx][ny] == 'G') {
              uni(i, j, nx, ny);
            }
          }
        }
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (ch[i][j] == 'G') {
          if (root(i, j) != root(n - 1, m - 1)) {
            ans = "No";
          }
        }
      }
    }
    if (cnt == 0) ans = "Yes";
    cout << ans << endl;
  }
  return 0;
}
