#include <bits/stdc++.h>
using namespace std;
long long cr[50][50];
void dfs(long long n, long long m, long long i, long long j) {
  cr[i][j] = 1;
  long long k;
  vector<long long> v1, v2;
  if (i != 0) v1.push_back(i - 1);
  if (i != n - 1) v1.push_back(i + 1);
  if (j != 0) v2.push_back(j - 1);
  if (j != m - 1) v2.push_back(j + 1);
  long long s1, s2;
  s1 = v1.size();
  s2 = v2.size();
  for (k = 0; k < s2; k++) {
    if (cr[i][v2[k]] == 0) {
      dfs(n, m, i, v2[k]);
    } else {
      return;
    }
  }
  for (k = 0; k < s1; k++) {
    if (cr[v1[k]][j] == 0) {
      dfs(n, m, v1[k], j);
    } else {
      return;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int T;
  cin >> T;
  while (T--) {
    long long i, j, k, n, m, x, y, z, q;
    long long sum = 0, ans = 0, f = 0;
    long long mx = INT_MAX;
    long long mn = INT_MIN;
    cin >> n >> m;
    string a[n];
    for (i = 0; i < n; i++) {
      cin >> a[i];
    }
    long long g = 0, b = 0;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        char w = a[i][j];
        if (w == '.' || w == '#')
          continue;
        else {
          if (w == 'G') {
            g++;
          } else {
            vector<long long> v1, v2;
            if (i != 0) v1.push_back(i - 1);
            if (i != n - 1) v1.push_back(i + 1);
            if (j != 0) v2.push_back(j - 1);
            if (j != m - 1) v2.push_back(j + 1);
            long long s1, s2;
            s1 = v1.size();
            s2 = v2.size();
            for (k = 0; k < s2; k++) {
              if (a[i][v2[k]] == 'G') {
                f = -1;
                break;
              } else if (a[i][v2[k]] == '.') {
                a[i][v2[k]] = '#';
              }
            }
            for (k = 0; k < s1; k++) {
              if (a[v1[k]][j] == 'G') {
                f = -1;
                break;
              } else if (a[v1[k]][j] == '.') {
                a[v1[k]][j] = '#';
              }
            }
          }
        }
      }
    }
    if (f != -1) {
      if (g == 0 && a[n - 1][m - 1] != 'B') {
        f = 0;
      } else if (a[n - 1][m - 1] == 'B') {
        f = -1;
      } else if (g > 0 && a[n - 1][m - 1] == '#') {
        f = -1;
      } else {
        memset(cr, 0, sizeof(cr));
        for (i = 0; i < n; i++) {
          for (j = 0; j < m; j++) {
            if (a[i][j] == 'B' || a[i][j] == '#')
              cr[i][j] = -1;
            else
              cr[i][j] == 0;
          }
        }
        cr[n - 1][m - 1] = 1;
        dfs(n, m, n - 1, m - 1);
        for (i = 0; i < n; i++) {
          for (j = 0; j < m; j++) {
            if (a[i][j] == 'G' && cr[i][j] != 1) {
              f = -1;
              break;
            }
          }
        }
      }
    }
    if (f == 0) {
      cout << "YES" << endl;
    } else {
      cout << "NO" << endl;
      ;
    }
  }
  return 0;
}
