#include <bits/stdc++.h>
using namespace std;
int n, m;
vector<string> arr(50);
vector<vector<int>> vis(50, vector<int>(50));
bool check(int i, int j) {
  int ok = 1;
  if (i + 1 < n) {
    ok &= arr[i + 1][j] != 'B';
  }
  if (i - 1 >= 0) {
    ok &= arr[i - 1][j] != 'B';
  }
  if (j + 1 < m) {
    ok &= arr[i][j + 1] != 'B';
  }
  if (j - 1 >= 0) {
    ok &= arr[i][j - 1] != 'B';
  }
  return ok;
}
void dfs(int i, int j) {
  if (i < 0 or j < 0 or j == m or i == n) return;
  if (arr[i][j] == 'B' or arr[i][j] == '#') return;
  if (!check(i, j)) return;
  if (vis[i][j]) return;
  vis[i][j] = 1;
  dfs(i - 1, j);
  dfs(i + 1, j);
  dfs(i, j - 1);
  dfs(i, j + 1);
}
int main() {
  ios::sync_with_stdio(false), cin.tie(NULL);
  int q;
  cin >> q;
  while (q--) {
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
      cin >> arr[i];
    }
    int c = 0;
    int has = 1;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (arr[i][j] == 'G' and !vis[i][j]) {
          dfs(i, j);
          c++;
          int ok = 1;
          has &= vis[n - 1][m - 1];
        }
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (arr[i][j] == 'G') has &= vis[i][j];
      }
    }
    if (!c) {
      if (arr[n - 1][m - 1] == 'B') {
        cout << "NO"
             << "\n";
        continue;
      } else {
        cout << "YES"
             << "\n";
        continue;
      }
    }
    if (arr[n - 1][m - 1] == 'B') {
      cout << "NO"
           << "\n";
      continue;
    }
    cout << (has ? "YES" : "NO") << "\n";
    vis.assign(50, vector<int>(50, 0));
  }
}
