import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,copy,functools
# import time,random,resource

# sys.setrecursionlimit(10**6)
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
mod2 = 998244353
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]

def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)
def pe(s): return print(str(s), file=sys.stderr)
def JA(a, sep): return sep.join(map(str, a))
def JAA(a, s, t): return s.join(t.join(map(str, b)) for b in a)
def IF(c, t, f): return t if c else f
def YES(c): return IF(c, "YES", "NO")
def Yes(c): return IF(c, "Yes", "No")


def main():
    t = I()

    rr = []
    for _ in range(t):
        n,m = LI()
        aa = [S() for _ in range(n)]

        gs = []
        for i in range(n):
            s = aa[i]
            for j in range(m):
                if s[j] == 'G':
                    gs.append((i,j))

        ok = 1
        t = [[0]*m for _ in range(n)]
        t[-1][-1] = -1
        for i in range(n):
            if not ok:
                break
            s = aa[i]
            for j in range(m):
                c = s[j]
                if c == '.':
                    continue
                b = 0
                if c == 'G':
                    b = -1
                elif c == '#':
                    b = 1
                else: # 'B'
                    b = -1
                    for di,dj in dd:
                        ni = i + di
                        nj = j + dj
                        if ni < 0 or ni >= n or nj < 0 or nj >= m or aa[ni][nj] == 'B':
                            continue
                        if t[ni][nj] == -1:
                            ok = 0
                            break
                        t[ni][nj] = 1

                if t[i][j] * b == -1:
                    ok = 0
                    break
                t[i][j] = b

        if len(gs) < 1:
            rr.append("YES")
        elif not ok:
            rr.append("NO")
        else:
            v = collections.defaultdict(bool)
            q = [(n-1,m-1)]
            v[(n-1,m-1)] = 1
            qi = 0
            o = [[None]*m for _ in range(n)]
            while qi < len(q):
                i,j = q[qi]
                qi += 1
                o[i][j] = 1
                for di,dj in dd:
                    ni = i + di
                    nj = j + dj
                    if ni < 0 or ni >= n or nj < 0 or nj >= m or t[ni][nj] == 1 or v[(ni,nj)]:
                        continue
                    v[(ni,nj)] = 1
                    q.append((ni,nj))

            rr.append(YES(all(o[i][j] for i,j in gs)))

    return JA(rr, "\n")


print(main())


