def DFS(maze, good):
    n = len(maze)
    m = len(maze[0])
    stack = [(n-1, m-1)]
    directions = [[-1, 0], [1, 0], [0, -1], [0, 1]]
    maze[-1][-1] = "#"
    visited_good = set()
    while stack:
        position = stack.pop()
        maze[position[0]][position[1]] = "#"
        blocked = False
        new_positions = []
        new_good = []
        for direction in directions:
            if 0 <= position[0] + direction[0] < n and 0 <= position[1] + direction[1] < m:
                if maze[position[0] + direction[0]][position[1] + direction[1]] == "G":
                    new_positions.append((position[0] + direction[0], position[1] + direction[1]))
                    new_good.append((position[0] + direction[0], position[1] + direction[1]))
                elif maze[position[0] + direction[0]][position[1] + direction[1]] == ".":
                    new_positions.append((position[0] + direction[0], position[1] + direction[1]))
                elif maze[position[0] + direction[0]][position[1] + direction[1]] == "B":
                    blocked = True
                    break

        if not blocked:
            stack.extend(new_positions)
            for g in new_good:
                visited_good.add(g)

    if len(visited_good) == good:
        print("YES")
    else:
        print("NO")




for _ in range(int(input())):
    n, m = map(int, input().split())
    maze = [[c for c in input()] for _ in range(n)]
    good = 0
    for row in maze:
        for x in row:
            if x == "G":
                good += 1
    DFS(maze, good)
