#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 10;
char g[55][55];
vector<pair<int, int>> pg;
void io() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
}
int n, m;
int vis[55][55];
int to[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
int len1, len2;
struct node {
  int x, y;
  node(){};
  node(int _x, int _y) : x(_x), y(_y){};
};
int bfs(int x, int y) {
  queue<node> q;
  node temp;
  for (int i = 0; i < 55; i++) memset(vis[i], 0, sizeof(vis[i]));
  q.push(node(x, y));
  while (!q.empty()) {
    temp = q.front();
    q.pop();
    int xx = temp.x, yy = temp.y;
    if (xx < 0 || yy < 0 || xx >= n || yy >= m) continue;
    if (g[xx][yy] == '#') continue;
    if (vis[xx][yy]) continue;
    vis[xx][yy] = 1;
    if (xx == n - 1 && yy == m - 1) return 1;
    for (int i = 0; i < 4; i++) q.push(node(xx + to[i][0], yy + to[i][1]));
  }
  return 0;
}
int excape() {
  for (int i = len1 - 1; i >= 0; i--) {
    for (int j = 0; j < 55; j++) memset(vis[j], 0, sizeof(vis[j]));
    if (!bfs(pg[i].first, pg[i].second)) return 0;
  }
  return 1;
}
int block(int x, int y) {
  for (int i = 0; i < 4; i++) {
    if (x + to[i][0] >= 0 && x + to[i][0] < n && y + to[i][1] >= 0 &&
        y + to[i][1] < m)
      g[x + to[i][0]][y + to[i][1]] = '#';
  }
  return 0;
}
int main(int argc, char const *argv[]) {
  io();
  int t;
  cin >> t;
  for (int i = 0; i < 55; i++) memset(g[i], 0, sizeof(g[i]));
  while (t--) {
    pg.clear();
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> g[i][j];
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (g[i][j] == 'G')
          pg.push_back(make_pair(i, j));
        else if (g[i][j] == 'B') {
          block(i, j);
        }
      }
    }
    int ok = 1;
    len1 = pg.size();
    if (!excape()) ok = 0;
    if (ok)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
  return 0;
}
