#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    int g = 0;
    char matrix[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> matrix[i][j];
        if (matrix[i][j] == 'G') g++;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (matrix[i][j] == 'B') {
          matrix[i][j] = '#';
          if (i - 1 >= 0) matrix[i - 1][j] = '#';
          if (i + 1 < n) matrix[i + 1][j] = '#';
          if (j - 1 >= 0) matrix[i][j - 1] = '#';
          if (j + 1 < m) matrix[i][j + 1] = '#';
        }
      }
    }
    set<pair<int, int>> vis;
    queue<pair<int, int>> q;
    q.push(make_pair(n - 1, m - 1));
    vis.insert(make_pair(n - 1, m - 1));
    int g_vis = 0;
    while (!q.empty()) {
      pair<int, int> temp = q.front();
      q.pop();
      int x = temp.first;
      int y = temp.second;
      vis.insert(make_pair(x, y));
      if (matrix[x][y] == 'G') {
        g_vis++;
      }
      if (x - 1 >= 0) {
        if (matrix[x - 1][y] != '#' &&
            vis.find(make_pair(x - 1, y)) == vis.end()) {
          q.push(make_pair(x - 1, y));
          vis.insert(make_pair(x - 1, y));
        }
      }
      if (x + 1 < n) {
        if (matrix[x + 1][y] != '#' &&
            vis.find(make_pair(x + 1, y)) == vis.end()) {
          q.push(make_pair(x + 1, y));
          vis.insert(make_pair(x + 1, y));
        }
      }
      if (y - 1 >= 0) {
        if (matrix[x][y - 1] != '#' &&
            vis.find(make_pair(x, y - 1)) == vis.end()) {
          q.push(make_pair(x, y - 1));
          vis.insert(make_pair(x, y - 1));
        }
      }
      if (y + 1 < m) {
        if (matrix[x][y + 1] != '#' &&
            vis.find(make_pair(x, y + 1)) == vis.end()) {
          q.push(make_pair(x, y + 1));
          vis.insert(make_pair(x, y + 1));
        }
      }
    }
    if (g_vis == g) {
      if (g > 0 && matrix[n - 1][m - 1] == '#')
        cout << "NO\n";
      else
        cout << "YES\n";
    } else
      cout << "NO\n";
  }
}
