#include <bits/stdc++.h>
using namespace std;
bool f;
bool vis[51][51];
void daal(int i, int j, int n, int m, string *str) {
  if (i >= 0 && i < n && j >= 0 && j < m && str[i][j] == '.') {
    str[i][j] = '#';
  }
}
bool dfs1(int i, int j, int n, int m, string *str) {
  if (i < 0 || j < 0 || i >= n || j >= m || str[i][j] == '#' ||
      vis[i][j] == true) {
    return false;
  }
  if (i == n - 1 && j == m - 1) {
    return true;
  }
  vis[i][j] = true;
  return dfs1(i - 1, j, n, m, str) || dfs1(i + 1, j, n, m, str) ||
         dfs1(i, j - 1, n, m, str) || dfs1(i, j + 1, n, m, str);
}
bool dfs2(int i, int j, int n, int m, string *str) {
  if (i < 0 || j < 0 || i >= n || j >= m || str[i][j] == '#' ||
      vis[i][j] == true) {
    return false;
  }
  if (i == n - 1 && j == m - 1) {
    return true;
  }
  vis[i][j] = true;
  return dfs2(i - 1, j, n, m, str) || dfs2(i + 1, j, n, m, str) ||
         dfs2(i, j - 1, n, m, str) || dfs2(i, j + 1, n, m, str);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int tc = 1;
  cin >> tc;
  while (tc--) {
    int n, m;
    cin >> n >> m;
    string s[n];
    map<char, int> cnt;
    for (int i = 0; i < n; i++) {
      cin >> s[i];
      for (int j = 0; j < m; j++) {
        cnt[s[i][j]]++;
      }
    }
    if (cnt.count('B') == 0 && s[n - 1][m - 1] != '#') {
      cout << "YES" << endl;
    } else {
      f = true;
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          vis[i][j] = false;
          if (s[i][j] == 'B') {
            daal(i - 1, j, n, m, s);
            daal(i + 1, j, n, m, s);
            daal(i, j - 1, n, m, s);
            daal(i, j + 1, n, m, s);
          }
        }
      }
      for (int i = 0; i < n; i++) {
        for (int j = 0; j < m; j++) {
          if (vis[i][j] == false) {
            if (s[i][j] == 'G') {
              if (dfs1(i, j, n, m, s) == false) {
                f = false;
              }
            }
            if (s[i][j] == 'B') {
              if (dfs2(i, j, n, m, s) == true) {
                f = false;
              }
            }
          }
        }
      }
      cout << (f == true ? "YES" : "NO") << endl;
    }
  }
}
