# -*- coding: utf-8 -*-
"""
Created on Tue Jun 30 07:07:41 2020

@author: Dark Soul
"""

def isSafe( maze, x, y , N, M): 
      
    if x >= 0 and x < N and y >= 0 and y < M and maze[x][y] == 1: 
        return True
      
    return False
def solveMaze(maze,N,M,i,j): 
      
    # Creating a 4 * 4 2-D list 
    sol = [ [ 0 for m in range(M) ] for n in range(N) ] 

      
    if solveMazeUtil(maze, i, j, sol,N,M) == False: 
        return False
    
    return True
def solveMazeUtil(maze, x, y, sol,N,M): 
      
    # if (x, y is goal) return True 
    if x == N - 1 and y == M - 1 and maze[x][y]== 1: 
        sol[x][y] = 1
        
        return True
          
    # Check if maze[x][y] is valid 
    if isSafe(maze, x, y,N,M) == True: 
        # mark x, y as part of solution path 
        sol[x][y] = 1
          
        # Move forward in x direction 
        if solveMazeUtil(maze, x + 1, y, sol,N,M) == True: 
            return True
              
        # If moving in x direction doesn't give solution  
        # then Move down in y direction 
        if solveMazeUtil(maze, x, y + 1, sol,N,M) == True: 
            return True
#        if y-1>=0 and solveMazeUtil(maze, x, y - 1, sol,N,M) == True: 
#            return True
#        if x-1>=0 and solveMazeUtil(maze, x-1, y, sol,N,M) == True: 
#            return True
        # If none of the above movements work then  
        # BACKTRACK: unmark x, y as part of solution path 
        sol[x][y] = 0
        return False

        
        



t=int(input(''))
dim=[]
mz=[]
for i in range(t):
    rw=list(map(int, input('').split()))
    dim.append(rw)
    for i in range(rw[0]):
        mz.append(list(input('')))
indd=0
for i in range(t):
    gd=[]
    bad=[]
    wall=[]
    empty=[]
    maze=[]
    mazz=[]
    orr_mazz=[]
    my_row=dim[i][0]
    rind=0
    for j in range(indd,indd+my_row,1):
        
        mazz=mz[j].copy()
        orr_mazz.append(mz[j])
        for k in range(len(mazz)):
            if mazz[k]=='G':
                mazz[k]=1
                ind=[rind,k]
                gd.append(ind)
            elif mazz[k]=='B':
                mazz[k]=1
                ind=[rind,k]
                bad.append(ind)
            elif mazz[k]=='#':
                mazz[k]=0
                ind=[rind,k]
                wall.append(ind)
            else:
                
                mazz[k]=1
                ind=[rind,k]
                empty.append(ind)
        maze.append(mazz)
        rind=rind+1
    indd=indd+my_row
    if len(gd)==0:
        if dim[i][0]+dim[i][1]==2:
            if len(bad)==1:
                print('NO')
            else:
                print('YES')
                continue
        else:
            print('YES')
    elif len(bad)==0:
        sign=True
        for n in range(len(gd)):
            sign=solveMaze(maze,dim[i][0],dim[i][1],gd[n][0],gd[n][1])
            if sign==False:
                break
        if sign:
            print('YES')
            continue
        else:
            print('NO')
    else:
        sign=True
        for n in range(len(gd)):
            sign=solveMaze(maze,dim[i][0],dim[i][1],gd[n][0],gd[n][1])
            if sign==False:
                break
        if sign==False:
            print('NO')
            continue
        flag=False
        for n in range(len(bad)):
            flag=solveMaze(maze,dim[i][0],dim[i][1],bad[n][0],bad[n][1])
            if flag==True:
                break
        if flag==False and sign==True:
            
            print('YES')
            continue
        else:
            for n in range(len(bad)):
                r=bad[n][0]
                c=bad[n][1]
                try:
                    if r+1<len(maze) and maze[r+1][c]!=0 and orr_mazz[r+1][c]=='.':
                        maze[r+1][c]=0
                except:
                    c=c
                try:        
                    if c+1<len(maze[0]) and maze[r][c+1]!=0 and orr_mazz[r][c+1]=='.':
                        maze[r][c+1]=0
                except:
                    c=c
                    
        sign=True
        for n in range(len(gd)):
            sign=solveMaze(maze,dim[i][0],dim[i][1],gd[n][0],gd[n][1])
            if sign==False:
                break
        flag=False
        for n in range(len(bad)):
            flag=solveMaze(maze,dim[i][0],dim[i][1],bad[n][0],bad[n][1])
            if flag==True:
                print(maze,dim[i][0],dim[i][1],bad[n][0],bad[n][1])
                break
        if flag==False and sign==True:
            print('YES')
            continue
        else:
           
            print('NO')
            
            
    