def dfs(i,j):
	if arr[i][j]=='#':
		return 0
 
	ans=0
	if arr[i][j]=='G':
		ans+=1
	if arr[i][j]=='B':
		return -100000
	arr[i][j]='#'
 
	if (i>0):
		ans+=dfs(i-1,j)
	if (i<n-1):
		ans+=dfs(i+1,j)
	if (j>0):
		ans+=dfs(i,j-1)
	if (j<m-1):
		ans+=dfs(i,j+1)
 
	return ans

for t in range(int(input())):
    n,m=map(int,input().split())
    arr=[]
    for i in range(n):
        arr.append(list(input()))
    good=0
    for i in range(n):
        for j in range(m):
            #print(i,j)
            if arr[i][j]=='G':
                good+=1
            if arr[i][j]=='B':
                if i>0:
                    arr[i-1][j]='#'
                if j<m-1:
                    arr[i][j+1]='#'
                if i+1<n:
                    arr[i+1][j]='#'
                if j-1>=0:
                    arr[i][j-1]='#'

    
    if dfs(n-1,m-1)==good:
        print('YES')
    else:
        print('NO')