
from sys import stdin
from collections import deque

tt = int(stdin.readline())

for loop in range(tt):

    n,m = map(int,stdin.readline().split())

    a = []
    for i in range(n):
        tmp = stdin.readline()
        a.append(list(tmp[:-1]))

    #print (a)

    flag = True
    goodnum = 0
    for i in range(n):
        for j in range(m):
            if a[i][j] == "B":
                
                if i != 0 and a[i-1][j] == ".":
                    a[i-1][j] = "#"
                if i != n-1 and a[i+1][j] == ".":
                    a[i+1][j] = "#"
                if j != 0 and a[i][j-1] == ".":
                    a[i][j-1] = "#"
                if j != m-1 and a[i][j+1] == ".":
                    a[i][j+1] = "#"

                if i != 0 and a[i-1][j] == "G":
                    flag = False
                if i != n-1 and a[i+1][j] == "G":
                    flag = False
                if j != 0 and a[i][j-1] == "G":
                    flag = False
                if j != m-1 and a[i][j+1] == "G":
                    flag = False
            elif a[i][j] == "G":
                goodnum += 1
    
    if not flag or a[-1][-1] == "#":
        if goodnum == 0:
            print ("Yes")
        else:
            print ("No")
        continue

    able = [[True] * m for i in range(n)]
    q = deque([(n-1,m-1)])
    able[-1][-1] = False

    ngood = 0
    while len(q) > 0:

        x,y = q.popleft()
        if a[x][y] == "G":
            ngood += 1
        i = x
        j = y

        if x != 0 and a[i-1][j] != "#" and able[i-1][j]:
            able[i-1][j] = False
            q.append((i-1,j))
        if x != n-1 and a[i+1][j] != "#" and able[i+1][j]:
            able[i+1][j] = False
            q.append((i+1,j))

        if y != 0 and a[i][j-1] != "#" and able[i][j-1]:
            able[i][j-1] = False
            q.append((i,j-1))
        if y != m-1 and a[i][j+1] != "#" and able[i][j+1]:
            able[i][j+1] = False
            q.append((i,j+1))

    if ngood == goodnum:
        print ("Yes")
    else:
        print ("No")
    
