import sys


sys.setrecursionlimit(10000)


R = lambda: map(int, input().split())
 
 
def findGoods(grid, visited, i, j):
    dr = [-1, 1, 0, 0]
    dc = [0, 0, 1, -1]
 
    visited[i][j] = True
    result = 0
 
    for d in range(4):
        ni, nc = i + dr[d], j + dc[d]
        if (0 <= ni < len(grid) and 0 <= nc < len(grid[0])) and not visited[ni][nc]:
            if grid[ni][nc] == '#':
                continue
            elif grid[ni][nc] == 'G':
                result += 1
            elif grid[ni][nc] == 'B':
                return -100000
 
            result += findGoods(grid, visited, ni, nc)
 
    return result
 
 
def bfs(grid, i, j):
    dr = [-1, 1, 0, 0]
    dc = [0, 0, 1, -1]
 
    for d in range(4):
        ni, nc = i + dr[d], j + dc[d]
        if 0 <= ni < len(grid) and 0 <= nc < len(grid[0]):
            if grid[ni][nc] == '.':
                grid[ni][nc] = '#'
 
 
T = int(input())
 
for t in range(T):
    n, m = R()
 
    grid = []
    bads = []
    goods = 0
 
    for i in range(n):
        line = input()
        grid.append(list(line))
 
    for i, line in enumerate(grid):
        for j, cell in enumerate(line):
            if cell == 'B':
                bads.append((i, j))
            elif cell == 'G':
                goods += 1
 
    for x, y in bads:
        bfs(grid, x, y)
 
    visited = list([False] * m for _ in range(n))
    escapable = findGoods(grid, visited, n - 1, m - 1)
 
    print('YES' if escapable == goods or goods == 0 else 'NO')