#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const double PI = acos(-1.0);
const int maxn = (int)5e5 + 13;
int tot, n, m;
bool replace(vector<vector<char>> &grid, int i, int j) {
  if (i < 0 || i >= n || j < 0 || j >= m) return true;
  if (grid[i][j] == 'G') return false;
  if (grid[i][j] = '.') grid[i][j] = '#';
  return true;
}
bool wall(vector<vector<char>> &grid, int i, int j) {
  bool res = replace(grid, i + 1, j) && replace(grid, i - 1, j) &&
             replace(grid, i, j + 1) && replace(grid, i, j - 1);
  return res;
}
void dfs(vector<vector<char>> &grid, int i, int j) {
  if (i < 0 || i >= n || j < 0 || j >= m) return;
  if (grid[i][j] == 'D' || grid[i][j] == 'B' || grid[i][j] == '#') return;
  if (grid[i][j] == 'G') ++tot;
  grid[i][j] = 'D';
  dfs(grid, i + 1, j);
  dfs(grid, i - 1, j);
  dfs(grid, i, j + 1);
  dfs(grid, i, j - 1);
}
void solve() {
  cin >> n >> m;
  tot = 0;
  vector<vector<char>> grid(n, vector<char>(m));
  int good = 0;
  for (int i = 0; i < (int)n; ++i) {
    for (int j = 0; j < (int)m; ++j) {
      cin >> grid[i][j];
      if (grid[i][j] == 'G') ++good;
    }
  }
  if (!good) {
    puts("Yes");
    return;
  }
  for (int i = 0; i < (int)n; ++i) {
    for (int j = 0; j < (int)m; ++j) {
      if (grid[i][j] == 'B') {
        if (!wall(grid, i, j)) {
          puts("No");
          return;
        }
      }
    }
  }
  if (grid[n - 1][m - 1] == '#' || grid[n - 1][m - 1] == 'B') {
    puts("No");
    return;
  }
  dfs(grid, n - 1, m - 1);
  puts(tot == good ? "Yes" : "No");
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
