def bfs(i,j):
    q=[(i,j)]
    vis={}
    dx=[-1,1,0,0]
    dy=[0,0,1,-1]
    c=0
    while q:
        x,y=q.pop(0)
        vis[(x,y)]=1
        for i in range(4):
            tx=x+dx[i]
            ty=y+dy[i]
            if 0<=tx<n and 0<=ty<m:
                if (tx,ty) in vis:
                    pass
                else:
                    if dp[tx][ty]==".":
                        q.append((tx,ty))
                    elif dp[tx][ty]=="G":
                        q.append((tx,ty))
                        c+=1
                    elif dp[tx][ty]=="#":
                        pass
                    else:
                        return -1
    return c

t=int(input())
for _ in range(t):
    n,m=map(int,input().split())
    dp=[[0]*m for _ in range(n)]
    ct=0
    for i in range(n):
        s=input()
        for j in range(m):
            dp[i][j]=s[j]
            if s[j]=="G":
                ct+=1
    for i in range(n):
        for j in range(m):
            if dp[i][j]=='.':
                if i-1>=0 and dp[i-1][j]=="B":
                    tf=True
                elif i+1<n and dp[i+1][j]=="B":
                    tf=True
                elif j-1>=0 and dp[i][j-1]=="B":
                    tf=True
                elif j+1<m and dp[i][j+1]=="B":
                    tf=True
                else:
                    tf=False
                if tf:
                    dp[i][j]="#"
    if dp[-1][-1]=="#":
        if ct==0:
            print("YES")
        else:
            print("NO")
    else:
        tp=bfs(n-1,m-1)
        if tp==-1:
            print('NO')
        else:
            if tp==ct:
                print('YES')
            else:
                print('NO')