#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
string ans[55];
int idx[4] = {0, 0, 1, -1};
int idy[4] = {1, -1, 0, 0};
int k = 0;
int n, m;
int cnt = 0;
void bfs1(int x, int y) {
  for (int i = 0; i < 4; i++) {
    int xx = x + idx[i];
    int yy = y + idy[i];
    if (xx >= 0 && xx < n && yy >= 0 && yy < m) {
      if (ans[xx][yy] == '.') {
        ans[xx][yy] = '#';
      }
    }
  }
}
void dfs(int x, int y) {
  for (int i = 0; i < 4; i++) {
    int xx = x + idx[i];
    int yy = y + idy[i];
    if (xx >= 0 && xx < n && yy >= 0 && yy < m) {
      if (ans[xx][yy] == 'G') {
        cnt++;
        ans[xx][yy] = '#';
        dfs(xx, yy);
      } else if (ans[xx][yy] == '.') {
        ans[xx][yy] = '#';
        dfs(xx, yy);
      }
    }
  }
}
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    k = 0;
    cnt = 0;
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) {
      cin >> ans[i];
    }
    int num = 0;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (ans[i][j] == 'B') {
          bfs1(i, j);
        }
        if (ans[i][j] == 'G') {
          num++;
        }
      }
    }
    if (ans[n - 1][m - 1] == '#') k = 1;
    dfs(n - 1, m - 1);
    if (cnt != num) {
      k = 1;
    }
    if (num == 0) k = 0;
    if (k) {
      puts("NO");
    } else {
      puts("YES");
    }
  }
  return 0;
}
