#include <bits/stdc++.h>
using namespace std;
const int N = 55;
int dr[] = {1, -1, 0, 0};
int dc[] = {0, 0, -1, 1};
int n, m, k, x, y, z, u, v, t, _g;
char grid[N][N];
map<pair<int, int>, int> triple;
bool vis[N][N] = {0}, found = false;
void filling_cells() {
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (grid[i][j] == 'B') {
        if (i + 1 < n && grid[i + 1][j] == '.') grid[i + 1][j] = '#';
        if (i - 1 >= 0 && grid[i - 1][j] == '.') grid[i - 1][j] = '#';
        if (j + 1 < m && grid[i][j + 1] == '.') grid[i][j + 1] = '#';
        if (j - 1 >= 0 && grid[i][j - 1] == '.') grid[i][j - 1] = '#';
      }
    }
  }
}
bool valid(int x, int y) {
  if (!vis[x][y] && x >= 0 && x < n && y >= 0 && y < m && grid[x][y] != '#')
    return true;
  return false;
}
void BFS() {
  queue<pair<int, int>> next_to_visit;
  next_to_visit.push({n - 1, m - 1});
  vis[n - 1][m - 1] = 1;
  if (_g && grid[n - 1][m - 1] == '#') {
    found = false;
    return;
  } else if (!_g && grid[n - 1][m - 1] == '#') {
    found = true;
    return;
  }
  while (!next_to_visit.empty()) {
    int x = next_to_visit.front().first;
    int y = next_to_visit.front().second;
    if (grid[x][y] == 'B')
      found = false;
    else if (grid[x][y] == 'G')
      _g--;
    next_to_visit.pop();
    vis[x][y] = 1;
    for (int k = 0; k < 4; ++k) {
      int currx = x + dr[k];
      int curry = y + dc[k];
      if (valid(currx, curry)) {
        next_to_visit.push({currx, curry});
        vis[currx][curry] = 1;
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    _g = 0;
    memset(vis, 0, sizeof(vis));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        cin >> grid[i][j];
        if (grid[i][j] == 'G') _g++;
      }
    }
    found = true;
    filling_cells();
    BFS();
    if (!found || _g)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }
  return 0;
}
