#include <bits/stdc++.h>
using namespace std;
long long ceildiv(long long one, long long two) {
  if (one % two == 0) {
    return one / two;
  } else {
    return one / two + 1;
  }
}
long long power(long long n, long long pow, long long m) {
  if (pow == 0) return 1;
  if (pow % 2 == 0) {
    long long x = power(n, pow / 2, m);
    return (x * x) % m;
  } else
    return (power(n, pow - 1, m) * n) % m;
}
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long factorial(long long n, long long mod) {
  if (n > 1)
    return (n * factorial(n - 1, mod)) % mod;
  else
    return 1;
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
vector<long long> read(long long n) {
  vector<long long> a;
  for (long long i = 0; i < n; i++) {
    long long x;
    cin >> x;
    a.push_back(x);
  }
  return a;
}
vector<vector<long long>> adj;
vector<bool> vis;
void dfs(long long u) {
  vis[u] = true;
  for (auto x : adj[u]) {
    if (!vis[x]) {
      dfs(x);
    }
  }
}
void solve() {
  long long n, m;
  cin >> n >> m;
  char a[n + 1][m + 1];
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      cin >> a[i][j];
    }
  }
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      if (a[i][j] == 'B') {
        if (i != 0) {
          if (a[i - 1][j] == 'G') {
            cout << "No" << '\n';
            return;
          } else if (a[i - 1][j] == '.') {
            a[i - 1][j] = '#';
          }
        }
        if (i != n - 1) {
          if (a[i + 1][j] == 'G') {
            cout << "No" << '\n';
            return;
          } else if (a[i + 1][j] == '.') {
            a[i + 1][j] = '#';
          }
        }
        if (j != 0) {
          if (a[i][j - 1] == 'G') {
            cout << "No" << '\n';
            return;
          } else if (a[i][j - 1] == '.') {
            a[i][j - 1] = '#';
          }
        }
        if (j != m - 1) {
          if (a[i][j + 1] == 'G') {
            cout << "No" << '\n';
            return;
          } else if (a[i][j + 1] == '.') {
            a[i][j + 1] = '#';
          }
        }
      }
    }
  }
  return;
  adj.clear();
  vis.clear();
  long long nd = 0;
  vector<long long> aa;
  adj.push_back(aa);
  vector<long long> good;
  for (long long i = 0; i < n; i++) {
    for (long long j = 0; j < m; j++) {
      adj.push_back(aa);
      nd++;
      if (a[i][j] == 'G') {
        good.push_back(nd);
      }
      if (a[i][j] == 'B' || a[i][j] == '#') continue;
      if (i != 0) {
        if (a[i - 1][j] != 'B' && a[i - 1][j] != '#') {
          adj[nd].push_back(nd - m);
        }
      }
      if (i != n - 1) {
        if (a[i + 1][j] != 'B' && a[i + 1][j] != '#') {
          adj[nd].push_back(nd + m);
        }
      }
      if (j != m - 1) {
        if (a[i][j + 1] != 'B' && a[i][j + 1] != '#') {
          adj[nd].push_back(nd + 1);
        }
      }
      if (j != 0) {
        if (a[i][j - 1] != 'B' && a[i][j - 1] != '#') {
          adj[nd].push_back(nd - 1);
        }
      }
    }
  }
  for (auto G : good) {
    vis.assign(n * m + 1, false);
    dfs(G);
    if (!vis[n * m]) {
      cout << "No" << '\n';
      return;
    }
  }
  cout << "Yes" << '\n';
}
int32_t main() {
  long long t = 1;
  cin >> t;
  while (t--) {
    solve();
  }
}
