from sys import stdin,setrecursionlimit
input=lambda:stdin.readline().strip()
setrecursionlimit(100000)
def block(x,y):
    if x+1<n:
        if arr[x+1][y]=='G':return 1
        arr[x+1][y]='#'
    if x:
        if arr[x-1][y]=='G':return 1
        arr[x-1][y]='#'
    if y+1<m:
        if arr[x][y+1]=='G':return 1
        arr[x][y+1]='#'
    if y:
        if arr[x][y-1]=='G':return 1
        arr[x][y-1]='#'
def dfs(x,y):
    global cnt
    if arr[x][y]=='G':cnt+=1
    arr[x][y]='#'
    if x+1<n and arr[x+1][y]!='#':dfs(x+1,y)
    if x     and arr[x-1][y]!='#':dfs(x-1,y)
    if y+1<m   and arr[x][y+1]!='#':dfs(x,y+1)
    if y     and arr[x][y-1]!='#':dfs(x,y-1)
for _ in range(int(input())):
    n,m=map(int,input().split())
    g=0
    b=[]
    arr=[]
    for i in range(n):
        s=input()
        for j in range(m):
            if s[j]=='G':g+=1
            elif s[j]=='B':b.append([i,j])
        arr.append(list(s))
    ans='YES'
    cnt=0
    for i,j in b:
        if block(i,j):ans='NO';break
    if ans=='NO'or arr[-1][-1]=='#'and g:print('NO');continue;
    dfs(n-1,m-1)
    print('YES'if cnt==g else 'NO')
#UPDATE!!!!!!!!!!!!!!
'''
1
3 6
BB#.GG
B.#B.G
.#.#G.
'''