import io
import os
from collections import deque


def bfs(source, getNbr):  # grid bfs
    q = deque([source])
    dist = {source: 0}
    while q:
        node = q.popleft()
        assert node in dist
        d = dist[node]
        for nbr in getNbr(node):
            if nbr not in dist:
                q.append(nbr)
                dist[nbr] = d + 1
    return dist


def solve(R, C, grid):

    drdc = [(-1, 0), (0, -1), (0, 1), (1, 0)]

    def getNbr(node):
        r, c = node
        for dr, dc in drdc:
            nr = r + dr
            nc = c + dc
            if 0 <= nr < R and 0 <= nc < C:
                yield nr, nc

    def getWalkableNbr(node):
        for nr, nc in getNbr(node):
            if grid[nr][nc] != "#":
                yield nr, nc

    goodCount = 0
    for r in range(R):
        for c in range(C):
            if grid[r][c] == "G":
                # Count good guys
                goodCount += 1
            if grid[r][c] == "B":
                # Wall bad guys in
                for nr, nc in getNbr((r, c)):
                    if grid[nr][nc] == "G":
                        # Can't wall
                        return "No"
                    if grid[nr][nc] == "B":
                        # Merge walls
                        continue
                    assert grid[nr][nc] in ".#"
                    grid[nr][nc] = "#"

    goodLeave = 0
    badLeave = 0
    if grid[R - 1][C - 1] != "#":
        source = (R - 1, C - 1)
        dist = bfs(source, getWalkableNbr)
        for r, c in dist.keys():
            if grid[r][c] == "G":
                goodLeave += 1
            if grid[r][c] == "B":
                badLeave += 1

    # Good guys who can't leave is zero and bad guys who can leave is zero
    if goodLeave == goodCount and badLeave == 0:
        return "Yes"
    return "No"


if __name__ == "__main__":
    input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

    T = int(input())
    for t in range(T):
        N, M = [int(x) for x in input().split()]
        grid = [list(input().decode().rstrip()) for i in range(N)]
        ans = solve(N, M, grid)
        print(ans)
