from sys import stdin
input = stdin.readline

def search(y, x):
    global g
    g += a[y][x] == "G"
    a[y][x] = "#"
    for i, j in ((y+1, x), (y-1, x), (y, x+1), (y, x-1)):
        if a[i][j] != "#":
            search(i, j)
        

t = int(input())
for _ in range(t):
    n, m = [int(x) for x in input().split()]
    a = [["#"]*(m+2)]
    a.extend([list("#" + input().strip() + "#") for _ in range(n)])
    a.append(["#"]*(m+2))
    c = 0
    p = False
    for y in range(1, n+1):
        for x in range(1, m+1):
            if a[y][x] == "B":
                if "G" in (a[y+1][x], a[y-1][x], a[y][x+1], a[y][x-1]):
                    p = True
                a[y+1][x] = a[y-1][x] = a[y][x+1] = a[y][x-1] = "#"
            elif a[y][x] == "G":
                c += 1
    if p:
        print("No")
        continue
    if c == 0:
        print("Yes")
        continue
    if a[-2][-2] == "#":
        print("No")
        continue
    g = 0
    search(n, m)
    if g == c:
        print("Yes")
    else:
        print("No")