#include <bits/stdc++.h>
using namespace std;
long long binpow(long long a, long long b) {
  a %= 1000000007;
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
    b >>= 1;
  }
  return res;
}
vector<vector<long long>> mult(vector<vector<long long>> a,
                               vector<vector<long long>> b) {
  vector<vector<long long>> c;
  for (long long i = 0; i < a.size(); i++) {
    vector<long long> v;
    for (long long j = 0; j < a[i].size(); j++) {
      long long x = 0;
      for (long long k = 0; k < b[j].size(); k++) {
        x += (a[i][k] * b[k][j]) % 1000000007;
        x %= 1000000007;
      }
      v.push_back(x);
    }
    c.push_back(v);
  }
  return c;
}
string s[51];
long long n, m;
long long a[51][51] = {0};
bool isValid(long long i, long long j) {
  if (i < 0 || i >= n || j < 0 || j >= m) {
    return false;
  }
  if (a[i][j] == 1 || s[i][j] == '#') {
    return false;
  }
  return true;
}
void dfs(long long i, long long j) {
  a[i][j] = 1;
  if (isValid(i, j + 1)) {
    dfs(i, j + 1);
  }
  if (isValid(i, j - 1)) {
    dfs(i, j - 1);
  }
  if (isValid(i + 1, j)) {
    dfs(i + 1, j);
  }
  if (isValid(i - 1, j)) {
    dfs(i - 1, j);
  }
  return;
}
int32_t main() {
  long long t;
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (long long i = 0; i < n; i++) cin >> s[i];
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        a[i][j] = 0;
      }
    }
    long long flag = 0;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (s[i][j] == 'B') {
          if (isValid(i, j + 1) && s[i][j + 1] != 'B') {
            if (s[i][j + 1] == 'G') {
              flag = 1;
              break;
            } else {
              s[i][j + 1] = '#';
            }
          }
          if (isValid(i, j - 1) && s[i][j - 1] != 'B') {
            if (s[i][j - 1] == 'G') {
              flag = 1;
              break;
            } else {
              s[i][j - 1] = '#';
            }
          }
          if (isValid(i + 1, j) && s[i + 1][j] != 'B') {
            if (s[i + 1][j] == 'G') {
              flag = 1;
              break;
            } else {
              s[i + 1][j] = '#';
            }
          }
          if (isValid(i - 1, j) && s[i - 1][j] != 'B') {
            if (s[i - 1][j] == 'G') {
              flag = 1;
              break;
            } else {
              s[i - 1][j] = '#';
            }
          }
        }
      }
      if (flag == 1) {
        break;
      }
    }
    if (flag == 1 || s[n - 1][m - 1] == 'B') {
      cout << "NO" << '\n';
      continue;
    }
    if (isValid(n - 1, m - 1)) dfs(n - 1, m - 1);
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (s[i][j] == 'G' && a[i][j] == 0) {
          flag = 1;
          break;
        }
      }
      if (flag == 1) {
        break;
      }
    }
    if (flag == 1) {
      cout << "NO" << '\n';
    } else {
      cout << "YES" << '\n';
    }
  }
}
