import sys
input = sys.stdin.readline
from collections import deque

for T in range(int(input())) :
    n , m = list(map(int,input().split()))

    arr = []
    for i in range(n) :
        arr.append(list(input().strip()))

    ans =1
    cnt = 0
    x=1 
    for i in range(n) :
        for j in range(m) :
           
            if arr[i][j] == 'B' :
                if i+1 <n and  arr[i+1][j] == 'G' :
                    ans = -1
                    break
                elif i+1 <n and arr[i+1][j] == '.' :
                    arr[i+1][j]  = '#'
                if j+1 < m and arr[i][j+1] == 'G' :
                    ans =-1
                    break
                elif j+1< m  and arr[i][j+1] == '.' :
                    arr[i][j+1] = '#'
                if j -1 >= 0 and arr[i][j-1] =='G' :
                    ans = -1
                    break
                elif j-1 >=0 and arr[i][j-1] == '.' :
                    arr[i][j-1] = '#'
                if i  -1 >= 0 and arr[i-1][j] == 'G' :
                    ans = -1
                    break
                elif i -1>=0  and arr[i-1][j] == '.' :
                    arr[i-1][j] = '#'
            elif arr[i][j] == 'G' :
                cnt +=1
        


    if ans ==-1 :
        print("NO")
    elif cnt ==0  :
        print("YES")
   
    else :
        count = 0
        dq = deque()
        dq.append((n-1,m-1))
        visit =[[False]*m for i in range(n)]
        while dq :
            x,y = dq.popleft()
            visit[x][y] = True
            if arr[x][y] != '#'  :
                if arr[x][y] == 'G' :
                    count +=1
                if x -1 >=0 and visit[x-1][y] == False:
                    dq.append((x-1,y))
                    visit[x-1][y] = True
                if y-1 >=0 and visit[x][y-1] == False:
                    dq.append((x, y-1))
                    visit[x][y-1] = True
                if x +1 < n and visit[x+1][y] == False :
                    dq.append((x+1 ,y))
                    visit[x+1][y] = True
                if y +1 <m and visit[x][y+1] == False :
                    dq.append((x,y+1))
                    visit[x][y+1] = True
        if count == cnt :
            print("YES")
        else :
            print("NO")
                
                
                
            
        
                    
                    
                
