#include <bits/stdc++.h>
using namespace std;
const long long Mod = 1e9 + 7;
const int N = 55;
char grid[N][N];
bool vis[N][N];
int n, m;
bool boom(int i, int j) {
  if (i && grid[i - 1][j] == 'G') return true;
  if (i < n - 1 && grid[i + 1][j] == 'G') return true;
  if (j && grid[i][j - 1] == 'G') return true;
  if (j < m - 1 && grid[i][j + 1] == 'G') return true;
  if (i && grid[i - 1][j] == '.') grid[i - 1][j] = '#';
  if (i < n - 1 && grid[i + 1][j] == '.') grid[i + 1][j] = '#';
  if (j && grid[i][j - 1] == '.') grid[i][j - 1] = '#';
  if (j < m - 1 && grid[i][j + 1] == '.') grid[i][j + 1] = '#';
  return false;
}
void dfs(int i, int j) {
  if (i < 0 || i >= n || j < 0 || j >= m) return;
  if (vis[i][j]) return;
  if (grid[i][j] == '#') return;
  vis[i][j] = true;
  grid[i][j] = '$';
  dfs(i + 1, j);
  dfs(i - 1, j);
  dfs(i, j - 1);
  dfs(i, j + 1);
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int numCases = 1;
  cin >> numCases;
  for (int caseNo = 1; caseNo <= numCases; caseNo++) {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> grid[i][j];
      }
    }
    memset(vis, 0, sizeof(vis));
    bool ans = true;
    for (int i = 0; i < n && ans; i++) {
      for (int j = 0; j < m && ans; j++) {
        if (grid[i][j] == 'B') {
          if (boom(i, j)) {
            ans = false;
          }
        }
      }
    }
    dfs(n - 1, m - 1);
    for (int i = 0; i < n && ans; i++) {
      for (int j = 0; j < m && ans; j++) {
        if (grid[i][j] == 'G') {
          ans = false;
        }
      }
    }
    if (ans) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
    }
  }
}
