#include <bits/stdc++.h>
using namespace std;
int c, n, m;
string a[55];
void DFS(int x, int y) {
  if (x < 1 || y < 1 || x > n || y > m) return;
  if (a[x][y] != '.' && a[x][y] != 'G') return;
  if (a[x][y] == 'G') c--;
  a[x][y] = '#';
  DFS(x - 1, y);
  DFS(x + 1, y);
  DFS(x, y - 1);
  DFS(x, y + 1);
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    int i, j;
    cin >> n >> m;
    for (i = 01; i <= n; i++) {
      cin >> a[i];
      a[i] = '#' + a[i];
    }
    c = 0;
    for (i = 1; i <= n; i++) {
      for (j = 1; j <= m; j++) {
        if (a[i][j] == 'G') c++;
        if (a[i][j] == 'B') continue;
        if (i - 1 > 0 && a[i - 1][j] == 'B') a[i][j] = '#';
        if (i + 1 <= n && a[i + 1][j] == 'B') a[i][j] = '#';
        if (j - 1 > 0 && a[i][j - 1] == 'B') a[i][j] = '#';
        if (j + 1 <= m && a[i][j + 1] == 'B') a[i][j] = '#';
      }
    }
    DFS(n, m);
    if (c == 0)
      cout << "YES\n";
    else
      cout << "NO\n";
  }
}
