#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
const int max_n = 50;
bool visit[max_n][max_n];
bool ans;
int n, m;
void floodfill(int r, int c, string* grid) {
  if (r < 0 || r >= n || c < 0 || c >= m) return;
  if (grid[r][c] == 'B') {
    ans = false;
    return;
  }
  if (grid[r][c] == '#') return;
  if (visit[r][c]) return;
  visit[r][c] = 1;
  floodfill(r - 1, c, grid);
  floodfill(r + 1, c, grid);
  floodfill(r, c - 1, grid);
  floodfill(r, c + 1, grid);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int test = 1;
  cin >> test;
  while (test--) {
    cin >> n >> m;
    string grid[max_n];
    for (int i = 0; i < n; i++) cin >> grid[i];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (grid[i][j] == 'B') {
          if (i > 0 && grid[i - 1][j] == '.') grid[i - 1][j] = '#';
          if (j > 0 && grid[i][j - 1] == '.') grid[i][j - 1] = '#';
          if (i < n - 1 && grid[i + 1][j] == '.') grid[i + 1][j] = '#';
          if (j < m - 1 && grid[i][j + 1] == '.') grid[i][j + 1] = '#';
        }
      }
    }
    memset(visit, false, sizeof(visit));
    ans = true;
    floodfill(n - 1, m - 1, grid);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (grid[i][j] == 'G' && !visit[i][j]) ans = false;
      }
    }
    if (!ans)
      cout << "NO"
           << "\n";
    else
      cout << "YES"
           << "\n";
  }
}
