#include <bits/stdc++.h>
using namespace std;
int dir[4][2] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};
bool visited[55][55];
bool flag = false;
int n, m;
vector<vector<char>> a(55, vector<char>(55));
bool check(int x, int y, int n, int m) {
  if (x >= 0 && x < n && y >= 0 && y < m) return true;
  return false;
}
void dfs(int i, int j) {
  visited[i][j] = true;
  if (i == n - 1 && j == m - 1) {
    flag = true;
    return;
  }
  for (int k = 0; k < 4; k++) {
    int x1 = i + dir[k][0];
    int y1 = j + dir[k][1];
    if (check(x1, y1, n, m) && !visited[x1][y1] && a[x1][y1] != '#') {
      dfs(x1, y1);
    }
  }
}
void solve() {
  cin >> n >> m;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == 'B') {
        for (int k = 0; k < 4; k++) {
          int x1 = i + dir[k][0];
          int x2 = j + dir[k][1];
          if (check(x1, x2, n, m) && a[x1][x2] == '.') a[x1][x2] = '#';
        }
      }
    }
  }
  bool good = true;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      if (a[i][j] == 'G') {
        memset(visited, false, sizeof visited);
        flag = false;
        dfs(i, j);
        if (flag == false) {
          good = false;
        }
      }
    }
  }
  if (good == true)
    cout << "YES" << endl;
  else {
    cout << "NO" << endl;
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    solve();
  }
}
