#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;
int N = 3e5 + 5;
ifstream fin("test.txt");
void solve() {
  int n, m, cnt = 0;
  cin >> n >> m;
  vector<vector<int> > g(n, vector<int>(m, -1));
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++) {
      char c;
      cin >> c;
      if (c == 'G') {
        g[i][j] = 1;
        cnt++;
      }
      if (c == 'B') g[i][j] = 0;
      if (c == '#') g[i][j] = 9;
    }
  for (int i = 0; i < (n); i++)
    for (int j = 0; j < (m); j++) {
      if (g[i][j] != 0) continue;
      if (j > 0) {
        if (g[i][j - 1] == 1) {
          cout << "NO" << endl;
          return;
        }
        if (g[i][j - 1] != 0) g[i][j - 1] = 9;
      }
      if (j < m - 1) {
        if (g[i][j + 1] == 1) {
          cout << "NO" << endl;
          return;
        }
        if (g[i][j + 1] != 0) g[i][j + 1] = 9;
      }
      if (i > 0) {
        if (g[i - 1][j] == 1) {
          cout << "NO" << endl;
          return;
        }
        if (g[i - 1][j] != 0) g[i - 1][j] = 9;
      }
      if (i < n - 1) {
        if (g[i + 1][j] == 1) {
          cout << "NO" << endl;
          return;
        }
        if (g[i + 1][j] != 0) g[i + 1][j] = 9;
      }
    }
  vector<vector<bool> > used(n, vector<bool>(m));
  queue<pair<int, int> > q;
  q.push({n - 1, m - 1});
  int ans = 0;
  while (!q.empty()) {
    int x = q.front().first, y = q.front().second;
    q.pop();
    if (used[x][y] || g[x][y] == 9) continue;
    used[x][y] = 1;
    if (g[x][y] == 1) ans++;
    if (x > 0) q.push({x - 1, y});
    if (x < n - 1) q.push({x + 1, y});
    if (y > 0) q.push({x, y - 1});
    if (y < m - 1) q.push({x, y + 1});
  }
  if (ans == cnt)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}
int main() {
  int t;
  cin >> t;
  while (t--) solve();
  ;
}
