#include <bits/stdc++.h>
using namespace std;
long long int visited[2505];
long long int dfs(long long int i, long long int j, long long int n,
                  long long int m, string s[]) {
  if (visited[m * i + j] == 1) return 0;
  if (s[i][j] == 'G') visited[m * i + j] = 1;
  long long int w = 0, x = 0, y = 0, z = 0;
  if (i == n - 1 && j == m - 1 &&
      (s[n - 1][m - 1] == '.' || s[n - 1][m - 1] == 'G'))
    return 1;
  else if (i == n - 1 && j == m - 1 &&
           (s[n - 1][m - 1] == '#' || s[n - 1][m - 1] == 'B'))
    return 0;
  if (i - 1 >= 0) {
    if (s[i - 1][j] == 'G')
      w = dfs(i - 1, j, n, m, s);
    else if (s[i - 1][j] == '.')
      w = dfs(i - 1, j, n, m, s);
    else
      w = 0;
    if (w == 1) goto r;
  }
  if (i + 1 < n) {
    if (s[i + 1][j] == 'G')
      x = dfs(i + 1, j, n, m, s);
    else if (s[i + 1][j] == '.')
      x = dfs(i + 1, j, n, m, s);
    else
      x = 0;
    if (x == 1) goto r;
  }
  if (j - 1 >= 0) {
    if (s[i][j - 1] == 'G')
      y = dfs(i, j - 1, n, m, s);
    else if (s[i][j - 1] == '.')
      y = dfs(i, j - 1, n, m, s);
    else
      y = 0;
    if (y == 1) goto r;
  }
  if (j + 1 < m) {
    if (s[i][j + 1] == 'G')
      z = dfs(i, j + 1, n, m, s);
    else if (s[i][j + 1] == '.')
      z = dfs(i, j + 1, n, m, s);
    else
      z = 0;
  }
r:
  return (w | x | y | z);
}
long long int dfsb(long long int i, long long int j, long long int n,
                   long long int m, string s[]) {
  if (visited[m * i + j] == 1) return 0;
  if (s[i][j] == 'B') visited[m * i + j] = 1;
  long long int w = 0, x = 0, y = 0, z = 0;
  if (i == n - 1 && j == m - 1 &&
      (s[n - 1][m - 1] == 'B' || s[n - 1][m - 1] == 'G' ||
       s[n - 1][m - 1] == '.')) {
    s[i][j] = '#';
    return 1;
  }
  if (i - 1 >= 0) {
    if (s[i - 1][j] == 'G' || s[i - 1][j] == 'B')
      w = dfsb(i - 1, j, n, m, s);
    else if (s[i - 1][j] == '.') {
      w = 1;
      s[i - 1][j] = '#';
    } else
      w = 0;
    if (w == 1) goto r;
  }
  if (i + 1 < n) {
    if (s[i + 1][j] == 'G' || s[i + 1][j] == 'B')
      x = dfsb(i + 1, j, n, m, s);
    else if (s[i + 1][j] == '.') {
      x = 1;
      s[i + 1][j] = '#';
    } else
      x = 0;
    if (x == 1) goto r;
  }
  if (j - 1 >= 0) {
    if (s[i][j - 1] == 'G' || s[i][j - 1] == 'B')
      y = dfsb(i, j - 1, n, m, s);
    else if (s[i][j - 1] == '.') {
      y = 1;
      s[i][j - 1] = '#';
    } else
      y = 0;
    if (y == 1) goto r;
  }
  if (j + 1 < m) {
    if (s[i][j + 1] == 'G' || s[i][j + 1] == 'B')
      z = dfsb(i, j + 1, n, m, s);
    else if (s[i][j + 1] == '.') {
      z = 1;
      s[i][j + 1] = '#';
    } else
      z = 0;
  }
r:
  return (w | x | y | z);
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int t, n, m, i, j, k, l, x;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    string s[n];
    for (i = 0; i < n; i++) cin >> s[i];
    memset(visited, 0, sizeof(visited));
    for (i = 0; i < n; i++)
      for (j = 0; j < m; j++) {
        if (s[i][j] == 'B' && visited[m * i + j] == 0) {
          dfsb(i, j, n, m, s);
        }
      }
    memset(visited, 0, sizeof(visited));
    if (n == 1 && m == 1) {
      if (s[0][0] == 'G' || s[0][0] == '.' || s[0][0] == '#')
        cout << "YES"
             << "\n";
      else
        cout << "NO"
             << "\n";
      for (i = 0; i < n; i++) s[i] = "";
      continue;
    }
    x = 1;
    for (i = 0; i < n; i++) {
      for (j = 0; j < m; j++) {
        if (s[i][j] == 'G') {
          if (visited[m * i + j] == 1) continue;
          x = dfs(i, j, n, m, s);
          if (x == 0) break;
        }
      }
      if (x == 0) break;
    }
    if (x)
      cout << "YES\n";
    else
      cout << "NO\n";
    for (i = 0; i < n; i++) s[i] = "";
  }
  return 0;
}
