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