#include <bits/stdc++.h>
using namespace std;
int n, m;
int di[] = {-1, 0, 1, 0};
int dj[] = {0, 1, 0, -1};
char grid[51][51];
bool visit[51][51];
bool valid(int i, int j) { return i < n && i >= 0 && j < m && j >= 0; }
bool block(int i, int j) {
  int ni, nj;
  for (int l = 0; l < 4; l++) {
    ni = i + di[l];
    nj = j + dj[l];
    if (valid(ni, nj)) {
      if (grid[ni][nj] == 'G' || (ni == n - 1 && j == m - 1)) return 0;
      if (grid[ni][nj] == '.') {
        grid[ni][nj] = '#';
      }
    }
  }
  return 1;
}
bool escape(int i, int j) {
  if (i == n - 1 && j == m - 1) return grid[i][j] != '#';
  visit[i][j] = 1;
  if (grid[i][j] == 'e') {
    return 1;
  }
  bool can = 0;
  int ni, nj;
  for (int l = 0; l < 4; l++) {
    ni = i + di[l];
    nj = j + dj[l];
    if (valid(ni, nj) && !visit[ni][nj] &&
        (grid[ni][nj] == '.' || grid[ni][nj] == 'G')) {
      can |= escape(ni, nj);
    }
  }
  if (can) grid[i][j] = 'e';
  return can;
}
int main() {
  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 No = 0;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        if (grid[i][j] == 'B') {
          if (!block(i, j)) {
            i = n;
            No = 1;
            break;
          }
        }
      }
    bool G = 0;
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        if (grid[i][j] == 'G') {
          G = 1;
          memset(visit, 0, sizeof(visit));
          if (!escape(i, j)) {
            i = n;
            No = 1;
            break;
          }
        }
      }
    if (No && G)
      cout << "No\n";
    else
      cout << "Yes\n";
  }
}
