#include <bits/stdc++.h>
using namespace std;
void check(int x, int y, int m, int n, int c[][52], int s[][52], int &kt) {
  if (x == m && y == n) {
    kt = 1;
    return;
  }
  s[x][y] = 1;
  if (x < m && c[x + 1][y] == 0 && s[x + 1][y] == 0)
    check(x + 1, y, m, n, c, s, kt);
  if (x > 0 && c[x - 1][y] == 0 && s[x - 1][y] == 0)
    check(x - 1, y, m, n, c, s, kt);
  if (y < n && c[x][y + 1] == 0 && s[x][y + 1] == 0)
    check(x, y + 1, m, n, c, s, kt);
  if (y > 0 && c[x][y - 1] == 0 && s[x][y - 1] == 0)
    check(x, y - 1, m, n, c, s, kt);
}
int main() {
  int t;
  scanf("%d", &t);
  while (t--) {
    int n, m, kt = 0, kt1 = 1;
    char a[52][52], s[52][52];
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; i++) {
      scanf("%s", &a[i]);
    }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < m; j++) {
        s[i + 1][j + 1] = a[i][j];
      }
    int c[52][52], z[52][52];
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        c[i][j] = 0;
        z[i][j] = 0;
      }
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        if (s[i][j] == 'B') {
          c[i][j] = 1;
          c[i + 1][j] = 1;
          c[i - 1][j] = 1;
          c[i][j + 1] = 1;
          c[i][j - 1] = 1;
        }
        if (s[i][j] == '#') {
          c[i][j] = 1;
        }
      }
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (s[i][j] == 'G') {
          kt = 0;
          check(j, i, m, n, c, z, kt);
          if (kt == 0) {
            kt1 = 0;
            break;
          }
        }
      }
    }
    if (kt1 == 0)
      printf("NO\n");
    else
      printf("YES\n");
  }
  return 0;
}
