def dfs(grid,x,y,n,m,visited):
    stack = [(x,y)]
    while stack:
        x,y = stack.pop()
        if (x,y) not in visited:
            visited.add((x,y))
            if x+1 < n and grid[x+1][y] != '#':
                stack.append((x+1,y))

            if y+1 < m and grid[x][y+1] != '#':
                stack.append((x,y+1))

            if x-1 >= 0 and grid[x-1][y] != '#':
                stack.append((x-1,y))

            if y-1 >= 0 and grid[x][y-1] != '#':
                stack.append((x,y-1))

def dfs2(grid,x,y,n,m,visited,visited2):
    stack = [(x,y)]
    while stack:
        x,y = stack.pop()
        if (x,y) in visited:
            return False
        if (x,y) not in visited2:
            visited2.add((x,y))
            if x+1 < n and grid[x+1][y] != '#':
                stack.append((x+1,y))

            if y+1 < m and grid[x][y+1] != '#':
                stack.append((x,y+1))

            if x-1 >= 0 and grid[x-1][y] != '#':
                stack.append((x-1,y))

            if y-1 >= 0 and grid[x][y-1] != '#':
                stack.append((x,y-1))

    return True

def solve(grid,n,m,ans):
    for i in range(n):
        for j in range(m):
            if grid[i][j] == 'B':
                if i+1 < n:
                    if grid[i+1][j] == '.':
                        grid[i+1][j] = '#'

                if j+1 < m:
                    if grid[i][j+1] == '.':
                        grid[i][j+1] = '#'

                if i-1 >= 0:
                    if grid[i-1][j] == '.':
                        grid[i-1][j] = '#'

                if j-1 >= 0:
                    if grid[i][j-1] == '.':
                        grid[i][j-1] = '#'

    good = 0
    for i in range(n):
        for j in range(m):
            if grid[i][j] == 'G':
                good += 1

    if good == 0:
        ans.append('Yes')
        return


    visited = set()
    for i in range(n):
        for j in range(m):
            if grid[i][j] == 'G':
                dfs(grid,i,j,n,m,visited)
                break
                

    if (n-1,m-1) not in visited:
        ans.append('No')
        return

    for i in range(n):
        for j in range(m):
            if grid[i][j] == 'G' and (i,j) not in visited:
                ans.append('No')
                return

    visited2 = set()
    for i in range(n):
        for j in range(m):
            if grid[i][j] == 'B':
                if not dfs2(grid,i,j,n,m,visited,visited2):
                    ans.append('No')
                    return

    if (n-1,m-1) in visited2:
        ans.append('No')
        return      
                
    ans.append('Yes')
            
                

def main():
    t = int(input())
    ans = []
    for i in range(t):
        n,m = map(int,input().split())
        grid = []
        for j in range(n):
            grid.append(list(input()))

        solve(grid,n,m,ans)

    for i in ans:
        print(i)


main()
