#include <bits/stdc++.h>
using namespace std;
const int N = 100;
bool st[N][N];
pair<int, int> q[N * N];
int arr[N][N];
char str[N][N];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int n, m;
void bfs(int n, int m) {
  int hh = 0, tt = -1;
  st[n][m] = true;
  q[++tt] = {n, m};
  while (hh <= tt) {
    pair<int, int> t = q[hh++];
    int x = t.first, y = t.second;
    for (int i = 0; i < 4; i++) {
      int px = x + dx[i], py = y + dy[i];
      if (px < 1 || px > n || py < 1 || py > m) continue;
      if (str[px][py] == '#') continue;
      if (st[px][py]) continue;
      st[px][py] = true;
      q[++tt] = {px, py};
    }
  }
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    memset(st, 0, sizeof st);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      cin >> (str[i] + 1);
    }
    bool k = true;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (str[i][j] == 'G') k = false;
      }
    }
    if (k) {
      cout << "YES" << endl;
      continue;
    }
    bool flag = true;
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (str[i][j] == 'B') {
          for (int k = 0; k < 4; k++) {
            int px = i + dx[k], py = j + dy[k];
            if (px < 1 || px > n || py < 1 || py > m) continue;
            if (str[px][py] == 'G') flag = false;
            if (str[px][py] == 'B') continue;
            str[px][py] = '#';
          }
        }
      }
    }
    if (str[n][m] == '#' || str[n][m] == 'B') {
      cout << "NO" << endl;
      continue;
    }
    bfs(n, m);
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (str[i][j] == 'G' && !st[i][j]) flag = false;
      }
    }
    if (flag)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
  }
}
