#include <bits/stdc++.h>
using namespace std;
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) {
    bool flag = 0;
    int n, m;
    cin >> n >> m;
    vector<vector<int>> g(m * n, vector<int>(4, -1));
    for (int i = 0; i < m * n; i++) {
      if (i >= m) g[i][3] = i - m;
      if (i < (n - 1) * m) g[i][1] = i + m;
      if (i % m != 0) g[i][0] = i - 1;
      if (i % m != m - 1) g[i][2] = i + 1;
    }
    vector<char> a(m * n);
    for (int j = 0; j < m * n; j++) {
      cin >> a[j];
    }
    for (int k = 0; k < m * n; k++) {
      if (a[k] == 'B') {
        if (k >= m) {
          if (a[k - m] == '.') a[k - m] = '#';
          if (a[k - m] == 'G') flag = 1;
        }
        if (k < (n - 1) * m) {
          if (a[k + m] == '.') a[k + m] = '#';
          if (a[k + m] == 'G') flag = 1;
        }
        if (k % m != 0) {
          if (a[k - 1] == '.') a[k - 1] = '#';
          if (a[k - 1] == 'G') flag = 1;
        }
        if (k % m != m - 1) {
          if (a[k + 1] == '.') a[k + 1] = '#';
          if (a[k + 1] == 'G') flag = 1;
        }
      }
    }
    for (int l = 0; l < m * n; l++) {
      if (l >= m) {
        if (a[l - m] == '#') {
          g[l][3] = -1;
          g[l - m][1] = -1;
        }
      }
      if (l < (n - 1) * m) {
        if (a[l + m] == '#') {
          g[l][1] = -1;
          g[l + m][3] = -1;
        }
      }
      if (l % m != 0) {
        if (a[l - 1] == '#') {
          g[l][0] = -1;
          g[l - 1][2] = -1;
        }
      }
      if (l % m != m - 1) {
        if (a[l + 1] == '#') {
          g[l][2] = -1;
          g[l + 1][0] = -1;
        }
      }
    }
    queue<int> q;
    vector<bool> r(m * n, 0);
    q.push(m * n - 1);
    r[m * n - 1] = 1;
    while (!q.empty()) {
      for (auto u : g[q.front()]) {
        if (u != -1) {
          if (r[u] == 0) {
            q.push(u);
            r[u] = 1;
          }
        }
      }
      q.pop();
    }
    for (int p = 0; p < m * n; p++) {
      if ((a[p] == 'G') && (r[p] == 0)) {
        flag = 1;
      }
    }
    if (flag)
      cout << "No" << endl;
    else
      cout << "Yes" << endl;
  }
}
