#include <bits/stdc++.h>
using namespace std;
template <typename T>
void read(T &x) {
  cin >> x;
}
template <typename T, typename T0>
void read(T &x, T0 &y) {
  cin >> x >> y;
}
template <typename T, typename T0, typename T1>
void read(T &x, T0 &y, T1 &z) {
  cin >> x >> y >> z;
}
template <typename T, typename T0, typename T1, typename T2>
void read(T &x, T0 &y, T1 &z, T2 &w) {
  cin >> x >> y >> z >> w;
}
template <typename T, typename T0>
void read(pair<T, T0> &p) {
  cin >> p.fst >> p.scd;
}
template <typename T>
void read(vector<T> &oneD, long long int n) {
  for (long long int i = 0; i < n; i++) {
    read(oneD[i]);
  }
}
template <typename T>
void read(T oneD[], long long int n) {
  for (long long int i = 0; i < n; i++) {
    read(oneD[i]);
  }
}
template <typename T>
void write(T &x) {
  cout << x << " ";
}
template <typename T, typename T0>
void write(T &x, T0 &y) {
  cout << x << " " << y << "\n";
}
template <typename T, typename T0, typename T1>
void write(T &x, T0 &y, T1 &z) {
  cout << x << " " << y << " " << z << "\n";
}
template <typename T, typename T0, typename T1, typename T2>
void write(T &x, T0 &y, T1 &z, T2 &w) {
  cout << x << " " << y << " " << z << " " << w << "\n";
}
template <typename T, typename T0>
void write(pair<T, T0> &p) {
  write(p.fst);
  write(p.scd);
  cout << endl;
}
template <typename T>
void write(vector<T> &oneD) {
  for (long long int i = 0; i < oneD.size(); i++) {
    write(oneD[i]);
  }
  cout << endl;
}
template <typename T>
void write(T oneD[], int n) {
  for (long long int i = 0; i < n; i++) {
    write(oneD[i]);
  }
  cout << endl;
}
template <typename T, typename T0>
void write(map<T, T0> &mpp) {
  for (auto it : mpp) {
    write(it.fst);
    cout << ": ";
    write(it.scd);
    cout << "\n";
  }
  cout << endl;
}
inline bool isSquare(long long int x) {
  long long int s = sqrt(x);
  return (s * s == x);
}
inline bool isFib(long long int x) {
  return isSquare(5 * x * x + 4) || isSquare(5 * x * x - 4);
}
inline bool isPowerOfTwo(long long int x) {
  return ((1LL << (long long int)log2(x)) == x);
}
long long int extended_GCD(long long int a, long long int b, long long int &x,
                           long long int &y) {
  if (a == 0) {
    x = 0;
    y = 1;
    return b;
  }
  long long int x1, y1;
  long long int gcd = extended_GCD(b % a, a, x1, y1);
  x = y1 - (b / a) * x1;
  y = x1;
  return gcd;
}
vector<long long int> prime;
void sieve(long long int N) {
  bool isPrime[N + !1];
  for (long long int i = 0; i <= N; ++i) {
    isPrime[i] = true;
  }
  isPrime[0] = false;
  isPrime[1] = false;
  for (long long int i = 2; i * i <= N; ++i) {
    if (isPrime[i] == true) {
      for (long long int j = i * i; j <= N; j += i) isPrime[j] = false;
    }
  }
  for (long long int i = 2; i <= N; i++) {
    if (isPrime[i] == true) {
      prime.push_back(i);
    }
  }
}
long long int minPrime[(int)(1 * 1e6 + 10)];
void factorSieve(long long int n) {
  memset(minPrime, 0, sizeof(minPrime));
  for (long long int i = 2; i * i <= n; ++i) {
    if (minPrime[i] == 0) {
      for (long long int j = i * i; j <= n; j += i) {
        if (minPrime[j] == 0) {
          minPrime[j] = i;
        }
      }
    }
  }
  for (long long int i = 2; i <= n; ++i) {
    if (minPrime[i] == 0) {
      minPrime[i] = i;
    }
  }
}
long long int factorize(long long int n) {
  map<long long int, long long int> m;
  m.clear();
  while (n != 1) {
    m[minPrime[n]]++;
    n /= minPrime[n];
  }
  for (auto i : m) {
    if (i.second > 1) {
      return 0;
    }
  }
  return 1;
}
long long int modinv(long long int a, long long int mod = 1000000007) {
  long long int x, y, g;
  g = extended_GCD(a, mod, x, y);
  if (g != 1)
    return -1;
  else {
    if (x < 0) x += mod;
    return x;
  }
}
long long int find_x_CRT(long long int num[], long long int rem[],
                         long long int n) {
  long long int pro = 1;
  for (int i = (0); ((1) > 0 ? i < (n) : i > (n)); i += (1)) pro *= num[i];
  long long int res = 0;
  for (int i = (0); ((1) > 0 ? i < (n) : i > (n)); i += (1)) {
    long long int pp = pro / num[i];
    res += (rem[i] * modinv(pp, num[i]) * pp);
  }
  res %= pro;
  return res;
}
long long int power(long long int a, long long int b,
                    long long int m = 1000000007) {
  a %= m;
  long long int res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % m;
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
void precompute_NCR(vector<long long int> &fact) {
  const long long int N = 1e6 + 5;
  fact[0] = 1;
  for (int i = (1); ((1) > 0 ? i < ((N - 1)) : i > ((N - 1))); i += (1)) {
    long long int y = (i % 1000000007 * fact[i - 1] % 1000000007) % 1000000007;
    fact[i] = y;
  }
}
long long int NCR(vector<long long int> &fact, long long int N, long long int R,
                  long long int mod = 1000000007) {
  long long int n = fact[N];
  long long int r = fact[R];
  long long int n_r = fact[N - R];
  long long int y = (r % mod * n_r % mod) % mod;
  long long int z = modinv(y, mod);
  long long int ans = (n % mod * z % mod) % mod;
  return ans;
}
string to_string(char c) { return string(1, c); }
struct comp {
  bool operator()(pair<long long int, long long int> a,
                  pair<long long int, long long int> b) {
    if (a.first == b.first) {
      return a.second > b.second;
    }
    return a.first < b.first;
  }
};
bool cmp(array<long long int, 2> a, array<long long int, 2> b) {
  if (a[0] == b[0]) {
    return a[1] < b[1];
  }
  return a[0] > b[0];
}
const int fx[] = {0, +1, 0, -1};
const int fy[] = {-1, 0, +1, 0};
const long long int N = 50, mxN = 1e2;
long long int n, m, ok = 0;
string s[N + 1];
long long int vis[N + 1][N + 1];
bool safe(long long int i, long long int j) {
  return i >= 0 && i < n && j >= 0 && j < m && s[i][j] != '#';
}
bool dfs(long long int i, long long int j) {
  vis[i][j] = 1;
  if (i == n - 1 && j == m - 1) ok = 1;
  for (int k = (0); ((1) > 0 ? k < (4) : k > (4)); k += (1)) {
    long long int ni = i + fx[k], nj = j + fy[k];
    if (safe(ni, nj) && vis[ni][nj]) continue;
    if (safe(ni, nj)) dfs(ni, nj);
  }
}
void solve() {
  read(n, m);
  for (int i = (0); ((1) > 0 ? i < (n) : i > (n)); i += (1)) read(s[i]);
  long long int flag = 0, flag2 = 0, flag1 = 0;
  for (int i = (0); ((1) > 0 ? i < (n) : i > (n)); i += (1)) {
    for (int j = (0); ((1) > 0 ? j < (m) : j > (m)); j += (1)) {
      if (s[i][j] == 'G') flag1 = 1;
      if (s[i][j] == 'B') {
        for (int k = (0); ((1) > 0 ? k < (4) : k > (4)); k += (1)) {
          long long int ni = i + fx[k], nj = j + fy[k];
          if (safe(ni, nj)) {
            if (s[ni][nj] == 'G')
              flag = 1;
            else if (ni == n - 1 && nj == m - 1)
              flag2 = 1;
            else
              s[ni][nj] = '#';
          }
        }
      }
    }
  }
  if (flag || (flag2 && flag1))
    cout << "NO\n";
  else {
    for (int i = (0); ((1) > 0 ? i < (n) : i > (n)); i += (1)) {
      for (int j = (0); ((1) > 0 ? j < (m) : j > (m)); j += (1)) {
        ok = 0;
        if (s[i][j] == 'G' && !vis[i][j]) {
          dfs(i, j);
          if (!ok) flag = 1;
        }
      }
    }
    if (flag)
      cout << "NO\n";
    else
      cout << "YES\n";
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int t = 1;
  read(t);
  for (int i = (0); ((1) > 0 ? i < (t) : i > (t)); i += (1)) {
    solve();
  }
}
