t = int(input())

for _ in range(t):
    n, m = list(map(int, input().split()))
    grid = []
    for _ in range(n):
        grid.append(list(input()))

    def get_ns(i, j):
        ns = []
        for s_x, s_y in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
            if 0 <= i + s_x < n and 0 <= j + s_y < m and grid[i + s_x][j + s_y] != "#":
                ns.append((i + s_x, j + s_y))
        return ns

    def solve():
        good = set()
        for i in range(n):
            for j in range(m):
                if grid[i][j] == "G":
                    good.add((i, j))
                if grid[i][j] == "B":
                    for x, y in get_ns(i, j):
                        if grid[x][y] == "G":
                            return False
                        if grid[x][y] == ".":
                            grid[x][y] = "#"
        if not good:
            return True
        if grid[n - 1][m - 1] not in [".", "G"]:
            return False
        stack = [(n - 1, m - 1)]
        visited = set()
        while stack:
            x, y = stack.pop()
            if (x, y) in good:
                good.remove((x, y))
            for ns in get_ns(x, y):
                if ns not in visited:
                    visited.add(ns)
                    stack.append(ns)
        if good:
            return False
        return True

    ans = solve()
    if ans:
        print("Yes")
    else:
        print("No")
