import sys
sys.setrecursionlimit(int(pow(10,6)))

def get_neighbors(grid, i, j):
    lst = []
    if i > 0:
        lst.append((i - 1, j))
    if i < len(grid) - 1:
        lst.append((i + 1, j))
    if j > 0:
        lst.append((i, j - 1))
    if j < len(grid[0]) - 1:
        lst.append((i, j + 1))
    return lst


def solve():
    T = int(input())
    for _ in range(T):
        n, m = [int(s) for s in input().split(" ")]
        grid = []
        for _ in range(n):
            grid.append(list(input()))
        count = 0
        for i in range(len(grid)):
            for j in range(len(grid[0])):
                if grid[i][j] == 'G':
                    count += 1
                elif grid[i][j] == 'B':
                    for neighbor in get_neighbors(grid, i, j):
                        if grid[neighbor[0]][neighbor[1]] == '.':
                            grid[neighbor[0]][neighbor[1]] = '#'
        curr = (len(grid) - 1, len(grid[0]) - 1)
        if count == 0:
            print("Yes")
        elif grid[curr[0]][curr[1]] == '#' or grid[curr[0]][curr[1]] == 'B':
            print("No")
        else:
            ct = dfs(grid, curr)
            if ct == count:
                print("Yes")
            else:
                print("No")


def dfs(grid, curr):
    count = 0
    if grid[curr[0]][curr[1]] == 'G':
        count += 1
    if grid[curr[0]][curr[1]] == 'B':
        return -1000000
    grid[curr[0]][curr[1]] = '#'
    for n in get_neighbors(grid, curr[0], curr[1]):
        if grid[n[0]][n[1]] != '#':
            count += dfs(grid, n)
    return count


solve()
