def solve():
    n, m = map(int, input().split())
    a = [list(input()) for _ in range(n)]
    def bad(i, j):
        if i - 1 >= 0:
            if a[i - 1][j] == 'G':
                return False
            if a[i - 1][j] == '.':
                a[i - 1][j] = '$'
        if j - 1 >= 0:
            if a[i][j - 1] == 'G':
                return False
            if a[i][j - 1] == '.':
                a[i][j - 1] = '$'
        if i + 1 < n:
            if a[i + 1][j] == 'G':
                return False
            if a[i + 1][j] == '.':
                a[i + 1][j] = '$'
        if j + 1 < m:
            if a[i][j + 1] == 'G':
                return False
            if a[i][j + 1] == '.':
                a[i][j + 1] = '$'
        return True
    for i in range(n):
        for j in range(m):
            if a[i][j] == 'B':
                if not bad(i, j):
                    print('No')
                    return
    q = []
    vis = [[False] * m for _ in range(n)]
    if a[n - 1][m - 1] in 'GB.':
        q.append((n - 1, m - 1))
        vis[n - 1][m - 1] = True
    gc = 0
    while q:
        i, j = q.pop(0)
        if a[i][j] == 'G':
            gc += 1
        if a[i][j] == 'B':
            print('No')
            return
        if i - 1 >= 0 and a[i - 1][j] in 'GB.' and not vis[i - 1][j]:
            q.append((i - 1, j))
            vis[i - 1][j] = True
        if j - 1 >= 0 and a[i][j - 1] in 'GB.' and not vis[i][j - 1]:
            q.append((i, j - 1))
            vis[i][j - 1] = True
        if i + 1 < n and a[i + 1][j] in 'GB.' and not vis[i + 1][j]:
            q.append((i + 1, j))
            vis[i + 1][j] = True
        if j + 1 < m and a[i][j + 1] in 'GB.' and not vis[i][j + 1]:
            q.append((i, j + 1))
            vis[i][j + 1] = True
    rgc = 0
    for i in range(n):
        for j in range(m):
            if a[i][j] == 'G':
                rgc += 1
    if gc != rgc:
        print('No')
    else:
        print('Yes')
t = int(input())
for _ in range(t):
    solve()