from sys import stdin

rints = lambda: [int(x) for x in stdin.readline().split()]
str_inp = lambda n: [list(stdin.readline().strip()) for _ in range(n)]
valid = lambda x, y: 0 <= x < n and 0 <= y < m
dx, dy = [-1, 0, 1, 0, 1, -1, 1, -1], [0, 1, 0, -1, 1, -1, -1, 1]


def put():
    global good
    for i in range(n):
        for j in range(m):
            if maze[i][j] == 'B':
                for k in range(4):
                    nx, ny = i + dx[k], j + dy[k]

                    if valid(nx, ny):
                        if maze[nx][ny] == 'G':
                            return False

                        elif maze[nx][ny] != 'B':
                            maze[nx][ny] = '#'

            elif maze[i][j] == 'G':
                good += 1

    return True


def dfs():
    stack, visit = [(n - 1, m - 1)], [[0 for _ in range(m)] for _ in range(n)]
    visit[n - 1][m - 1], ans = 1, 0

    while stack:
        x, y = stack.pop()
        if maze[x][y] == 'G':
            ans += 1
        elif maze[x][y] == '#':
            continue

        for i in range(4):
            nx, ny = x + dx[i], y + dy[i]

            if valid(nx, ny) and not visit[nx][ny]:
                visit[nx][ny] = 1

                if maze[nx][ny] != '#':
                    stack.append((nx, ny))

    return ans


for _ in range(int(input())):
    n, m = rints()
    maze, good = str_inp(n), 0

    if not put() or good != dfs():
        print('No')
    else:
        print('Yes')

    # print(maze, good)
