import math,sys,bisect
from collections import defaultdict,Counter,deque
from itertools import groupby,accumulate
#sys.setrecursionlimit(1000000)
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
ilele = lambda: map(int,input().split())
alele = lambda: list(map(int, input().split()))
#def list2d(a, b, c): return [[c] * b for i in range(a)]
#def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
#MOD = 1000000000 + 7
def Y(c):  print(["NO","YES"][c])
def y(c):  print(["no","yes"][c])
def Yy(c):  print(["No","Yes"][c])
    
for _ in range(int(input())):
    n,m = ilele()
    A = []
    for i in range(n):
        B = input()
        A.append([*B])
    f= 0
    for i in A:
        if 'G' in i:
            f=1
            break
    if f==0:
        Yy(1)
    else:
        g=0
        for i in range(n):
            for j in range(m):
                if A[i][j] == "B":
                    u = A[max(i-1,0)][j]
                    d = A[min(n-1,i+1)][j]
                    l = A[i][max(0,j-1)]
                    r = A[i][min(m-1,j+1)]
                    if 'G' in [u,d,r,l]:
                        g=1
                        break
                    if u != 'B':    A[max(i-1,0)][j] = '#'
                    if d != 'B':    A[min(n-1,i+1)][j] = '#'
                    if l != 'B':    A[i][max(0,j-1)] = '#'
                    if r != 'B':    A[i][min(m-1,j+1)] = '#'
            if g==1:
                break
        if g==1 or A[n-1][m-1] == '#':
            Yy(0)
        else:
            #for i in A:
            #    print(*i)
            G = defaultdict(set)
            
            def addEdge(a,b):
                G[a].add(b)
                G[b].add(a)
                
            def DFSutil(node,vis):
                vis[node] = True
                for i in list(G[node]):
                    if vis[i] == False:
                        DFSutil(i,vis)

            def dfs(node):
                vis ={i:False for i in G.keys()}
                DFSutil(node,vis)
                return (False not in vis.values())
            g=1
            for i in range(n):
                for j in range(m):
                    if A[i][j] == "G":
                        g=0
                        u = A[max(i-1,0)][j]
                        d = A[min(n-1,i+1)][j]
                        l = A[i][max(0,j-1)]
                        r = A[i][min(m-1,j+1)]
                        if (u == 'G' or u == '.') and i != 0:
                            addEdge((i,j),(i-1,j))
                            g=1
                        if (d == 'G' or d == '.') and i != n-1:
                            addEdge((i,j),(i+1,j))
                            g=1
                        if (l == 'G' or l == '.') and j != 0:
                            addEdge((i,j),(i,j-1))
                            g=1
                        if (r == 'G' or r == '.') and j != m-1:
                            addEdge((i,j),(i,j+1))
                            g=1
                        if g==0:    break
                    
                    elif A[i][j] == '.':
                        u = A[max(i-1,0)][j]
                        d = A[min(n-1,i+1)][j]
                        l = A[i][max(0,j-1)]
                        r = A[i][min(m-1,j+1)]
                        if (u == 'G' or u == '.') and i != 0:
                            addEdge((i,j),(i-1,j))
                        if (d == 'G' or d == '.') and i != n-1:
                            addEdge((i,j),(i+1,j))
                        if (l == 'G' or l == '.') and j != 0:
                            addEdge((i,j),(i,j-1))
                        if (r == 'G' or r == '.') and j != m-1:
                            addEdge((i,j),(i,j+1))
                if g==0:    break
            #print(G)
            if G.get((n-1,m-1),[]) == [] or g==0:
                Yy(0)
            else:
                Yy(dfs((n-1,m-1)))
                
                
                




