#include <bits/stdc++.h>
using namespace std;
long long n, m, test, mark[52][52], ok, kt;
char a[52][52];
long long dx[4] = {0, 0, -1, 1};
long long dy[4] = {-1, 1, 0, 0};
long long check(long long x, long long y, long long k) {
  if (x + dx[k] < 0 || x + dx[k] > n) return (0);
  if (y + dy[k] < 0 || y + dy[k] > m) return (0);
  if (mark[x + dx[k]][y + dy[k]] == 1) return (0);
  if (a[x + dx[k]][y + dy[k]] == '#') return (0);
  return (1);
}
void ktra() {
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= m; j++) {
      if (a[i][j] == 'B')
        for (int k = 0; k < 4; k++) {
          if (a[i + dx[k]][j + dy[k]] == 'G') {
            cout << "NO" << endl;
            kt = 1;
            return;
          }
          if (a[i + dx[k]][j + dy[k]] != 'B') a[i + dx[k]][j + dy[k]] = '#';
        }
    }
}
void bfs(long long x, long long y) {
  queue<pair<long long, long long>> qu;
  qu.push(make_pair(x, y));
  memset(mark, 0, sizeof(mark));
  mark[x][y] = 1;
  while (qu.size()) {
    long long u, v;
    u = qu.front().first;
    v = qu.front().second;
    qu.pop();
    for (int i = 0; i < 4; i++)
      if (check(u, v, i) == 1) {
        long long b, c;
        b = u + dx[i];
        c = v + dy[i];
        if (b == n && c == m) return;
        qu.push(make_pair(b, c));
        mark[b][c] = 1;
      }
  }
  ok = 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> test;
  long long t = test;
  while (test--) {
    cin >> n >> m;
    ok = 0;
    kt = 0;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) {
        cin >> a[i][j];
      }
    ktra();
    if (kt == 1) continue;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++)
        if (a[i][j] == 'G') bfs(i, j);
    if (ok == 0)
      cout << "YES" << endl;
    else
      cout << "NO" << endl;
    for (int i = 1; i <= n; i++)
      for (int j = 1; j <= m; j++) a[i][j] = ' ';
  }
}
