#include <bits/stdc++.h>
using namespace std;
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, -1, 0, 1};
string arr[51];
int visited[51][51];
int flag = 0;
int n, m;
bool good, bad;
void bfs1(int sy, int sx) {
  queue<pair<int, int> > q;
  q.push({sy, sx});
  visited[sy][sx] = 1;
  while (!q.empty()) {
    int y = q.front().first;
    int x = q.front().second;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int yy = y + dy[i];
      int xx = x + dx[i];
      if (yy < 0 || xx < 0 || yy >= n || xx >= m) continue;
      if ((arr[yy][xx] == '.' || arr[yy][xx] == 'G') && !visited[yy][xx]) {
        q.push(make_pair(yy, xx));
        visited[yy][xx] = 1;
        if (yy == n - 1 && xx == m - 1) {
          flag = 1;
          return;
        }
      }
    }
  }
}
void bfs2(int sy, int sx) {
  queue<pair<int, int> > q;
  q.push({sy, sx});
  visited[sy][sx] = 1;
  while (!q.empty()) {
    int y = q.front().first;
    int x = q.front().second;
    cout << y << ' ' << x << endl;
    q.pop();
    for (int i = 0; i < 4; i++) {
      int yy = y + dy[i];
      int xx = x + dx[i];
      if (yy < 0 || xx < 0 || yy >= n || xx >= m) continue;
      if ((arr[yy][xx] == '.' || arr[yy][xx] == 'B') && !visited[yy][xx]) {
        q.push(make_pair(yy, xx));
        visited[yy][xx] = 1;
        if (yy == n - 1 && xx == m - 1) {
          flag = 1;
          return;
        }
      }
    }
  }
}
int main() {
  int t;
  cin >> t;
  while (t--) {
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> arr[i];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (arr[i][j] == 'B') {
          for (int k = 0; k < 4; k++) {
            int yy = i + dy[k];
            int xx = j + dx[k];
            if (yy < 0 || yy >= n || xx < 0 || xx >= m) continue;
            if (arr[yy][xx] == '.') arr[yy][xx] = '#';
          }
        }
      }
    }
    good = true, bad = true;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        if (arr[i][j] == 'G') {
          flag = 0;
          memset(visited, 0, sizeof(visited));
          bfs1(i, j);
          if (flag == 0) good = false;
        } else if (arr[i][j] == 'B') {
          flag = 0;
          memset(visited, 0, sizeof(visited));
          bfs2(i, j);
          if (flag == 1) bad = false;
        }
      }
    }
    if (good == true && bad == true)
      cout << "Yes\n";
    else
      cout << "No\n";
  }
}
