def isValid(x,y,n,m):
    if x<0 or x>n-1 or y<0 or y>m-1:
        return False
    if vis[x][y]==1 or matrix[x][y]=="#":
        return False
    return True
dx=[-1,0,1,0]
dy=[0,1,0,-1]
def dfs(x,y,n,m):
    stack=[[x,y]]
    vis[x][y]=1
    while stack:
        temp=stack.pop()
        curX=temp[0]
        curY=temp[1]
        for i in range(4):
            if isValid(curX+dx[i],curY+dy[i],n,m):
                newX=curX+dx[i]
                newY=curY+dy[i]
                vis[newX][newY]=1
                stack.append([newX,newY])
t=int(input())
for _ in range(t):
    n,m=list(map(int,input().split()))
    matrix=[]
    for i in range(n):
        s=str(input())
        lis=[]
        for j in range(m):
            lis.append(s[j])
        matrix.append(lis)
    a=0
    vis=[[0]*m for i in range(n)]
    for i in range(n):
        for j in range(m):
            if matrix[i][j]=="B":
                for k in range(4):
                    if isValid(i+dx[k],j+dy[k],n,m):
                        if matrix[i+dx[k]][j+dy[k]]=="G" or (i+dx[k]==n-1 and j+dy[k]==m-1):
                            a+=1
                            break
                        else:
                            matrix[i+dx[k]][j+dy[k]]="#"
    if a==1:
        print("NO")
    else:
        b=0
        for i in range(n):
            for j in range(m):
                if vis[i][j]==0 and matrix[i][j]=="G":
                    dfs(i,j,n,m)
                    b+=1
        if b<=1:
            print("YES")
        else:
            print("NO")
        
        
        
        
        