#include <bits/stdc++.h>
const int N = 1e6 + 5;
using namespace std;
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
int n, m;
char grid[50][50];
int visited[50][50] = {0};
void fill_grid(int i, int j) {
  if (i - 1 >= 0 && grid[i - 1][j] != '#' && grid[i - 1][j] != 'B' &&
      grid[i - 1][j] != '*') {
    grid[i - 1][j] = '*';
    fill_grid(i - 1, j);
  }
  if (j - 1 >= 0 && grid[i][j - 1] != '#' && grid[i][j - 1] != 'B' &&
      grid[i][j - 1] != '*') {
    grid[i][j - 1] = '*';
    fill_grid(i, j - 1);
  }
  if (i + 1 < n && grid[i + 1][j] != '#' && grid[i + 1][j] != 'B' &&
      grid[i + 1][j] != '*') {
    grid[i + 1][j] = '*';
    fill_grid(i + 1, j);
  }
  if (j + 1 < m && grid[i][j + 1] != '#' && grid[i][j + 1] != 'B' &&
      grid[i][j + 1] != '*') {
    grid[i][j + 1] = '*';
    fill_grid(i, j + 1);
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    bool ans = false;
    char matrix[50][50];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> grid[i][j];
        matrix[i][j] = grid[i][j];
        if (grid[i][j] == 'G') ans = true;
      }
    }
    bool flag = true;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (grid[i][j] == 'B') {
          char op1 = '.', op2 = '.', op3 = '.', op4 = '.';
          if (i - 1 >= 0) {
            op1 = grid[i - 1][j];
            if (op1 == '.') grid[i - 1][j] = '#';
          }
          if (j - 1 >= 0) {
            op2 = grid[i][j - 1];
            if (op2 == '.') grid[i][j - 1] = '#';
          }
          if (i + 1 < n) {
            op3 = grid[i + 1][j];
            if (op3 == '.') grid[i + 1][j] = '#';
          }
          if (j + 1 < m) {
            op4 = grid[i][j + 1];
            if (op4 == '.') grid[i][j + 1] = '#';
          }
          if ((op1 == 'G') || (op2 == 'G') || (op3 == 'G') || (op4 == 'G'))
            flag = false;
        }
      }
    }
    if (!ans) {
      cout << "Yes" << endl;
      continue;
    }
    if (!flag) {
      cout << "No" << endl;
      continue;
    }
    if (n - 2 >= 0 && m - 2 >= 0 &&
        (grid[n - 2][m - 2] == 'B' || grid[n - 2][m - 1] == 'B' ||
         grid[n - 1][m - 2] == 'B'))
      flag = false;
    grid[n - 1][m - 1] = '*';
    fill_grid(n - 1, m - 1);
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (matrix[i][j] == 'G') {
          if (grid[i][j] != '*') flag = false;
        }
      }
    }
    if (flag)
      cout << "Yes" << endl;
    else
      cout << "No" << endl;
  }
}
