# B and G can't be neighbors
# B and the final cell can't be neighbor as well
# fill in those cells and check if each B can reach the final cell
# start from the final cell and see each B can be reached
from collections import defaultdict
T = int(input())
for t in range(T):
    n, m = [int(i) for i in input().split()]
    A = [list(input()) for i in range(n)]
    for i in range(n):
        for j in range(m):
            if A[i][j] == 'B':
                if i >= 1 and A[i-1][j] == '.':
                    A[i-1][j] = '#'
                if j >= 1 and A[i][j-1] =='.':
                    A[i][j-1] = '#'
                if i < n-1 and A[i+1][j] == '.':
                    A[i+1][j] = '#'
                if j < m-1 and A[i][j+1] == '.':
                    A[i][j+1] = '#'
    # construct graph and then do dfs
    G = defaultdict(set)
    B_set = set()
    G_set = set()
    visited = dict()
    for i in range(n):
        for j in range(m):
            visited[(i,j)] = False
            if A[i][j] == 'B':
                B_set.add((i,j))
            elif A[i][j] == 'G':
                G_set.add((i,j))
            if A[i][j] != '#':
                if i < n-1 and A[i+1][j] != '#':
                    G[(i,j)].add((i+1,j))
                    G[(i+1,j)].add((i,j))
                if j < m-1 and A[i][j+1] != '#':
                    G[(i,j)].add((i, j+1))
                    G[(i,j+1)].add((i,j))
    if A[-1][-1] == '#':
        if len(G_set) > 0:
            print("No")
        else:
            print("Yes")
        continue
    Q = [(n-1, m-1)]
    visited[(n-1, m-1)] = True
    exit_flag = False
    visited_good = set()
    while Q and not exit_flag:
        u = Q.pop()
        for w in G[u]:
            if not visited[w]:
                Q.append(w)
                visited[w] = True
                if w in B_set:
                    exit_flag = True
                    print("No")
                    break
                if w in G_set:
                    visited_good.add(w)
    if not exit_flag:
        # now check if we visited all good cell
        if len(G_set.difference(visited_good)) > 0:
            print("No")
        else:
            print("Yes")
