#include <bits/stdc++.h>
using namespace std;
vector<string> v(100000);
int n, m;
bool check(int i, int j) {
  if (i < n && i >= 0 && j < m && j >= 0) {
    if (v[i][j] != '#') return true;
  }
  return false;
}
void dfs(int i, int j, vector<vector<bool> >& vis) {
  if (!check(i, j)) return;
  vis[i][j] = true;
  if (check(i, j + 1) && !vis[i][j + 1]) {
    dfs(i, j + 1, vis);
  }
  if (check(i, j - 1) && !vis[i][j - 1]) {
    dfs(i, j - 1, vis);
  }
  if (check(i - 1, j) && !vis[i - 1][j]) {
    dfs(i - 1, j, vis);
  }
  if (check(i + 1, j) && !vis[i + 1][j]) {
    dfs(i + 1, j, vis);
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    vector<vector<bool> > vis(n, vector<bool>(m, false));
    for (long long i = 0; i < n; i++) {
      cin >> v[i];
    }
    bool flag = true;
    int g = 0, b = 0;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (v[i][j] == 'G') g++;
        if (v[i][j] == 'B') b++;
      }
    }
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (v[i][j] == 'B') {
          if (check(i + 1, j)) {
            if (v[i + 1][j] == 'G') flag = false;
            if (v[i + 1][j] != 'B') v[i + 1][j] = '#';
          }
          if (check(i - 1, j)) {
            if (v[i - 1][j] == 'G') flag = false;
            if (v[i - 1][j] != 'B') v[i - 1][j] = '#';
          }
          if (check(i, j + 1)) {
            if (v[i][j + 1] == 'G') flag = false;
            if (v[i][j + 1] != 'B') v[i][j + 1] = '#';
          }
          if (check(i, j - 1)) {
            if (v[i][j - 1] == 'G') flag = false;
            if (v[i][j - 1] != 'B') v[i][j - 1] = '#';
          }
        }
      }
    }
    if (g == 0) {
      cout << "YES\n";
      continue;
    }
    int posi, posj;
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (v[i][j] == 'G') {
          posi = i;
          posj = j;
          i = n;
          break;
        }
      }
    }
    dfs(posi, posj, vis);
    for (long long i = 0; i < n; i++) {
      for (long long j = 0; j < m; j++) {
        if (v[i][j] == 'G' && vis[i][j] == false) {
          flag = false;
          break;
        }
      }
    }
    if (vis[n - 1][m - 1] == false) flag = false;
    if (flag == true)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
