#include <bits/stdc++.h>
using namespace std;
int adj[51][51];
bool visited[51][51];
bool flag;
int n, m;
int number;
int makewall(int i, int j) {
  if (i < 1 || i > n || j < 1 || j > m) {
    return 0;
  }
  if (adj[i][j] != 1 && adj[i][j] != -1) {
    adj[i][j] = 2;
  }
  return 0;
}
int solve(int i, int j) {
  if (adj[i][j] == -1) {
    makewall(i + 1, j);
    makewall(i - 1, j);
    makewall(i + 1, j + 1);
    makewall(i + 1, j);
    makewall(i + 1, j - 1);
    makewall(i - 1, j);
    makewall(i - 1, j - 1);
    makewall(i - 1, j + 1);
    if (adj[i][j + 1] == 1) {
      flag = 0;
    }
    if (adj[i + 1][j] == 1) {
      flag = 0;
    }
    if (adj[i][j - 1] == 1) {
      flag = 0;
    }
    if (adj[i - 1][j] == 1) {
      flag = 0;
    }
  }
  return 0;
}
int DFS(int i, int j) {
  if (i < 1 || i > n || j < 1 || j > m) {
    return 0;
  }
  if (!visited[i][j]) {
    visited[i][j] = 1;
    if (adj[i][j] == 1 || adj[i][j] == 0) {
      if (adj[i][j] == 1) {
        number++;
      }
      if (adj[i + 1][j] == 1 || adj[i + 1][j] == 0) {
        DFS(i + 1, j);
      }
      if (adj[i][j + 1] == 1 || adj[i][j + 1] == 0) {
        DFS(i, j + 1);
      }
      if (adj[i][j - 1] == 1 || adj[i][j - 1] == 0) {
        DFS(i, j - 1);
      }
      if (adj[i - 1][j] == 1 || adj[i - 1][j] == 0) {
        DFS(i - 1, j);
      }
    }
  }
  return 0;
}
int main() {
  int T;
  cin >> T;
  while (T--) {
    memset(adj, 0, sizeof(adj));
    memset(visited, 0, sizeof(visited));
    cin >> n >> m;
    int count1 = 0;
    int count2 = 0;
    char a;
    flag = 1;
    for (int i = 1; i < n + 1; i++) {
      for (int j = 1; j < m + 1; j++) {
        cin >> a;
        if (a == '.') {
          adj[i][j] = 0;
        } else if (a == 'G') {
          adj[i][j] = 1;
          count1++;
        } else if (a == 'B') {
          adj[i][j] = -1;
          count2++;
        } else {
          adj[i][j] = 2;
        }
      }
    }
    for (int i = 1; i < n + 1; i++) {
      for (int j = 1; j < m + 1; j++) {
        solve(i, j);
      }
    }
    if (flag == 0) {
      cout << "No" << endl;
    } else {
      number = 0;
      DFS(n, m);
      if (number == count1) {
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
  }
  return 0;
}
