def solve(n, m, maze):
    for i in range(n):
        for j in range(m):
            if maze[i][j] != "B":
                continue

            if i > 0:
                if maze[i - 1][j] == "G":
                    return False
                if maze[i - 1][j] == ".":
                    maze[i - 1][j] = "#"
            if j > 0:
                if maze[i][j - 1] == "G":
                    return False
                if maze[i][j - 1] == ".":
                    maze[i][j - 1] = "#"
            if i < n - 1:
                if maze[i + 1][j] == "G":
                    return False
                if maze[i + 1][j] == ".":
                    maze[i + 1][j] = "#"
            if j < m - 1:
                if maze[i][j + 1] == "G":
                    return False
                if maze[i][j + 1] == ".":
                    maze[i][j + 1] = "#"

    reachables = set()
    to_visit = {(n - 1, m - 1)} if maze[n - 1][m - 1] != "#" else set()
    while to_visit:
        i, j = to_visit.pop()
        reachables.add((i, j))
        if i > 0 and maze[i - 1][j] != '#' and (i - 1, j) not in reachables:
            to_visit.add((i - 1, j))
        if i < n - 1 and maze[i + 1][j] != '#' and (i + 1, j) not in reachables:
            to_visit.add((i + 1, j))
        if j > 0 and maze[i][j - 1] != '#' and (i, j - 1) not in reachables:
            to_visit.add((i, j - 1))
        if j < m - 1 and maze[i][j + 1] != '#' and (i, j + 1) not in reachables:
            to_visit.add((i, j + 1))

    for i in range(n):
        for j in range(m):
            if maze[i][j] == "B" and (i, j) in reachables:
                return False
            if maze[i][j] == "G" and (i, j) not in reachables:
                return False

    return True


def main():
    T = int(input())
    for _ in range(T):
        n, m = map(int, input().split())
        maze = [list(input().strip()) for _ in range(n)]
        print("Yes" if solve(n, m, maze) else "No")


if __name__ == "__main__":
    main()
