from collections import deque
def rec(i,imp,t,par):
    if i==t or t in par[i]:
        imp.add(t)
        return
    imp.add(par[i])
    rec(par[i],imp,t,par)
for _ in range(int(input())):
    n,m=map(int,input().split())
    mat=[]
    g=0
    b=0
    gl=[]
    bl=[]
    par={}
    for j in range(n):
        s=input()
        ll=[]
        for i in range(m):
            if s[i]=='#':
                ll.append(float('inf'))
            if s[i]=='G':
                ll.append(1)
                g+=1
                gl.append((j,i))
            if s[i]=='B':
                ll.append(-1)
                b+=1
                bl.append((j,i))    
            if s[i]=='.':
                ll.append(0)
        mat.append(ll)
    if mat[n-1][m-1]==float('inf'):
        print('No')
        continue
    q=deque([(n-1,m-1)])
    vis=[[False]*m for _ in range(n)]
    vis[n-1][m-1]=True 
    while q:
        rmv=q.popleft()
        for dx in range(-1,2):
            for dy in range(-1,2):
                if abs(dx)+abs(dy)==1:
                    ni,nj=rmv[0]+dx,rmv[1]+dy
                    if ni>=0 and nj>=0 and ni<n and nj<m and not vis[ni][nj] and mat[ni][nj]!=float('inf'):
                        vis[ni][nj]=True
                        par[(ni,nj)]=(rmv[0],rmv[1])
                        q.append((ni,nj))
                        
    
    allgs=True
    for i in gl:
        allgs=allgs and vis[i[0]][i[1]]
    if allgs  and b==0 or g==0:
        print('Yes')
        continue
    if not allgs:
        print('No')
        continue
    imp=set()
    for i in gl:
        rec(i,imp,(n-1,m-1),par)
    for i in range(n):
        for j in range(m):
            if (i,j) not in imp and mat[i][j]==0:
                mat[i][j]=float('inf')
    
    q=deque([(n-1,m-1)])
    vis=[[False]*m for _ in range(n)]
    vis[n-1][m-1]=True 
    while q:
        rmv=q.popleft()
        for dx in range(-1,2):
            for dy in range(-1,2):
                if abs(dx)+abs(dy)==1:
                    ni,nj=rmv[0]+dx,rmv[1]+dy
                    if ni>=0 and nj>=0 and ni<n and nj<m and not vis[ni][nj] and mat[ni][nj]!=float('inf'):
                        vis[ni][nj]=True
                        par[(ni,nj)]=(rmv[0],rmv[1])
                        q.append((ni,nj))
    allgs=True
    for i in gl:
        allgs=allgs and vis[i[0]][i[1]]
    allbs=False
    for i in bl:
        allbs=allbs or vis[i[0]][i[1]]
    if allgs and not allbs:
        print('Yes')
    else:
        print('No')
    
    