#include <bits/stdc++.h>
using namespace std;
void dfs(int i, int j, vector<vector<char>>& g, vector<vector<bool>>& used) {
  used[i][j] = true;
  if (!used[i - 1][j] && g[i - 1][j] != '#') dfs(i - 1, j, g, used);
  if (!used[i + 1][j] && g[i + 1][j] != '#') dfs(i + 1, j, g, used);
  if (!used[i][j - 1] && g[i][j - 1] != '#') dfs(i, j - 1, g, used);
  if (!used[i][j + 1] && g[i][j + 1] != '#') dfs(i, j + 1, g, used);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    vector<vector<char>> g(n + 2, vector<char>(m + 2, '.'));
    bool exactly = false;
    bool haveG = false;
    for (int i = 0; i < n + 2; ++i) {
      g[i][0] = '#';
      g[i][m + 1] = '#';
    }
    for (int i = 1; i <= m; ++i) {
      g[0][i] = '#';
      g[n + 1][i] = '#';
    }
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) {
        char c;
        cin >> c;
        if (c == 'B') {
          if (g[i - 1][j] == 'G')
            exactly = true;
          else
            g[i - 1][j] = '#';
          if (g[i + 1][j] == 'G')
            exactly = true;
          else
            g[i + 1][j] = '#';
          if (g[i][j - 1] == 'G')
            exactly = true;
          else
            g[i][j - 1] = '#';
          if (g[i][j + 1] == 'G')
            exactly = true;
          else
            g[i][j + 1] = '#';
        }
        if (c == 'G') {
          haveG = true;
          if (g[i - 1][j] == 'B') exactly = true;
          if (g[i + 1][j] == 'B') exactly = true;
          if (g[i][j - 1] == 'B') exactly = true;
          if (g[i][j + 1] == 'B') exactly = true;
        }
        if (c != '.') g[i][j] = c;
      }
    vector<vector<bool>> used(n + 2, vector<bool>(m + 2, false));
    dfs(n, m, g, used);
    bool yes = true;
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) {
        if (g[i][j] == 'G')
          if (!used[i][j]) yes = false;
      }
    if (exactly || !yes || (g[n][m] == '#' && haveG))
      cout << "NO\n";
    else
      cout << "YES\n";
  }
  return 0;
}
