#include <bits/stdc++.h>
template <typename T>
T GCD(T a, T b) {
  return a ? GCD(b % a, a) : b;
}
template <typename T>
T LCM(T a, T b) {
  return (a * b) / GCD(a, b);
}
using ld = double;
using ll = long long int;
using ul = unsigned long long int;
using namespace std;
class DSolveTheMaze {
  char maze[51][51];
  bool visited[51][51];
  int cnt = 0;
  stack<pair<int, int>> s;
  void CanEscape(int i, int j, int n, int m) {
    cout << i << ' ' << j << endl;
    int path = 0, p, q;
    if (maze[i][j] == 'G' && !visited[i][j]) cnt++;
    visited[i][j] = true;
    if (i + 1 < n && (maze[i + 1][j] == '.' || maze[i + 1][j] == 'G') &&
        !visited[i + 1][j])
      path++;
    if (i - 1 >= 0 && (maze[i - 1][j] == '.' || maze[i - 1][j] == 'G') &&
        !visited[i - 1][j])
      path++;
    if (j + 1 < m && (maze[i][j + 1] == '.' || maze[i][j + 1] == 'G') &&
        !visited[i][j + 1])
      path++;
    if (j - 1 >= 0 && (maze[i][j - 1] == '.' || maze[i][j - 1] == 'G') &&
        !visited[i][j - 1])
      path++;
    if (path > 1) s.push(make_pair(i, j));
    if (i + 1 < n && (maze[i + 1][j] == '.' || maze[i + 1][j] == 'G') &&
        !visited[i + 1][j])
      CanEscape(i + 1, j, n, m);
    else if (i - 1 >= 0 && (maze[i - 1][j] == '.' || maze[i - 1][j] == 'G') &&
             !visited[i - 1][j])
      CanEscape(i - 1, j, n, m);
    else if (j - 1 >= 0 && (maze[i][j - 1] == '.' || maze[i][j - 1] == 'G') &&
             !visited[i][j - 1])
      CanEscape(i, j - 1, n, m);
    else if (j + 1 < m && (maze[i][j + 1] == '.' || maze[i][j + 1] == 'G') &&
             !visited[i][j + 1])
      CanEscape(i, j + 1, n, m);
    else if (!s.empty()) {
      p = s.top().first;
      q = s.top().second;
      bool up = true, down = true, left = true, right = true;
      if (p - 1 >= 0 && (maze[p - 1][q] == '.' || maze[p - 1][q] == 'G')) {
        if (visited[p - 1][q]) up = false;
      } else
        up = false;
      if (p + 1 < n && (maze[p + 1][q] == '.' || maze[p - 1][q] == 'G')) {
        if (visited[p + 1][q]) down = false;
      } else
        down = false;
      if (q + 1 < m && (maze[p][q + 1] == '.' || maze[p - 1][q] == 'G')) {
        if (visited[p][q + 1]) right = false;
      } else
        right = false;
      if (q - 1 >= 0 && (maze[p][q - 1] == '.' || maze[p - 1][q] == 'G')) {
        if (visited[p][q - 1]) left = false;
      } else
        left = false;
      if (up || down || left || right) {
        CanEscape(s.top().first, s.top().second, n, m);
      } else {
        s.pop();
        if (!s.empty()) CanEscape(s.top().first, s.top().second, n, m);
      }
    }
  }

 public:
  void solve(std::istream &in, std::ostream &out) {
    int n, m, totgood = 0;
    cnt = 0;
    in >> n >> m;
    for (int i = 0; i < 51; i++) {
      for (int j = 0; j < 51; j++) {
        maze[i][j] = '1';
        visited[i][j] = false;
      }
    }
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        in >> maze[i][j];
        if (maze[i][j] == 'G') totgood++;
      }
    }
    bool neg = false;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (maze[i][j] == 'B') {
          if (i + 1 < n && maze[i + 1][j] == '.') maze[i + 1][j] = '#';
          if (i - 1 >= 0 && maze[i - 1][j] == '.') maze[i - 1][j] = '#';
          if (j - 1 >= 0 && maze[i][j - 1] == '.') maze[i][j - 1] = '#';
          if (j + 1 < m && maze[i][j + 1] == '.') maze[i][j + 1] = '#';
          if (i + 1 < n && maze[i + 1][j] == 'G') neg = true;
          if (i - 1 >= 0 && maze[i - 1][j] == 'G') neg = true;
          if (j - 1 >= 0 && maze[i][j - 1] == 'G') neg = true;
          if (j + 1 < m && maze[i][j + 1] == 'G') neg = true;
        }
      }
    }
    if (totgood == 0) {
      out << "Yes" << endl;
      return;
    }
    if (maze[n - 1][m - 1] != '.' || neg) {
      out << "No" << endl;
      return;
    }
    CanEscape(n - 1, m - 1, n, m);
    if (totgood == cnt)
      out << "Yes" << endl;
    else
      out << "No" << endl;
  }
};
int main() {
  std::ios_base::sync_with_stdio(0);
  std::cin.tie(nullptr);
  DSolveTheMaze solver;
  std::istream &in(std::cin);
  std::ostream &out(std::cout);
  int n;
  in >> n;
  for (int i = 0; i < n; ++i) {
    solver.solve(in, out);
  }
  return 0;
}
