#include <bits/stdc++.h>
using namespace std;
int dx[5] = {0, 0, 1, -1};
int dy[5] = {1, -1, 0, 0};
char a[55][55];
int vis[55][55];
int n, m;
int xx = 0;
bool bfs(int x, int y) {
  vis[x][y] = 1;
  int ans = 0;
  queue<pair<int, int>> q;
  q.push(make_pair(x, y));
  while (!q.empty()) {
    pair<int, int> np = q.front();
    q.pop();
    for (int k = 0; k < 4; ++k) {
      int nx = np.first + dx[k], ny = np.second + dy[k];
      if (nx >= 1 && nx <= n && ny >= 1 && ny <= m && a[nx][ny] != '#' &&
          !vis[nx][ny]) {
        if (a[nx][ny] == 'G') ans++;
        q.push(make_pair(nx, ny));
        vis[nx][ny] = 1;
      }
    }
  }
  bool f = 0;
  if (ans == xx) f = 1;
  return f;
}
int main() {
  int te;
  cin >> te;
  while (te--) {
    memset(a, 0, sizeof(a));
    memset(vis, 0, sizeof(vis));
    xx = 0;
    cin >> n >> m;
    for (int i = 1; i <= n; ++i)
      for (int j = 1; j <= m; ++j) {
        cin >> a[i][j];
        if (a[i][j] == 'G') xx++;
      }
    if (xx == 0) {
      puts("Yes");
      continue;
    }
    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) {
            int nx = i + dx[k], ny = j + dy[k];
            if (nx >= 1 && nx <= n && ny >= 1 && ny <= m)
              if (a[nx][ny] == '.')
                a[nx][ny] = '#';
              else if (a[nx][ny] == 'G')
                goto aaa;
          }
        }
    if (a[n][m] != '#' && bfs(n, m)) {
      puts("Yes");
      continue;
    }
  aaa:
    puts("No");
  }
  return 0;
}
