#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long int;
using ld = long double;
using namespace std;
using vll = vector<ll>;
using vvll = vector<vll>;
using vi = vector<int>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vpii = vector<pii>;
using vvi = vector<vi>;
int n, m;
char grid[50][50];
void dfs(int i, int j) {
  if (i < 0 || i >= n || j < 0 || j >= m || grid[i][j] == '#') return;
  grid[i][j] = '#';
  dfs(i + 1, j);
  dfs(i - 1, j);
  dfs(i, j - 1);
  dfs(i, j + 1);
}
int main() {
  iostream::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> grid[i][j];
      }
    }
    bool cando = 1;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (grid[i][j] == 'B') {
          if (i > 0) {
            auto& g = grid[i - 1][j];
            if (g == 'G')
              cando = 0;
            else
              g = '#';
          }
          if (i < n - 1) {
            auto& g = grid[i + 1][j];
            if (g == 'G')
              cando = 0;
            else
              g = '#';
          }
          if (j > 0) {
            auto& g = grid[i][j - 1];
            if (g == 'G')
              cando = 0;
            else
              g = '#';
          }
          if (j < m - 1) {
            auto& g = grid[i][j + 1];
            if (g == 'G')
              cando = 0;
            else
              g = '#';
          }
        }
      }
    }
    if (cando) {
      dfs(n - 1, m - 1);
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (grid[i][j] == 'G') cando = 0;
        }
      }
    }
    if (cando)
      cout << "YES" << '\n';
    else
      cout << "NO" << '\n';
  }
}
