def neighbors(position, rows, cols):
    r, c = position
    neighbors = []
    for candidate in [(r - 1, c), (r + 1, c), (r, c - 1), (r, c + 1)]:
        new_r, new_c = candidate
        if new_r < 0 or new_r >= rows or new_c < 0 or new_c >= cols:
            continue
        else:
            neighbors.append(candidate)
    return neighbors

def check_maze(rows, cols, maze, good_person_positions, bad_person_positions):
    for b in bad_person_positions:
        for neighbor in neighbors(b, rows, cols):
            r, c = neighbor

            # Borders a good person
            if neighbor in good_person_positions:
                return 'NO'
            
            if maze[r][c] == '.':
                maze[r][c] = '#'
    
    if len(good_person_positions) > 0 and maze[rows - 1][cols - 1] == '#':
        return 'NO'

    queue = [(rows - 1, cols - 1)]
    visited = {}
    while len(queue) > 0 and len(good_person_positions) > 0:
        curr_position = queue.pop()
        if curr_position in visited:
            continue
        
        visited[curr_position] = 1
        if curr_position in good_person_positions:
            good_person_positions.remove(curr_position)
        
        r, c = curr_position
        if maze[r][c] == '#':
            continue

        queue += neighbors(curr_position, rows, cols)
    
    if len(good_person_positions) == 0:
        return 'YES'
    else:
        return 'NO'



T = int(input())
for _ in range(T):
    n, m = map(int, input().strip().split())
    good_person_positions, bad_person_positions = set(), set()
    maze = []
    for r in range(n):
        row = list(input().strip())
        for c, elem in enumerate(row):
            if elem == 'G':
                good_person_positions.add((r, c))
            elif elem == 'B':
                bad_person_positions.add((r, c))
        maze.append(row)
    
    print(check_maze(n, m, maze, good_person_positions, bad_person_positions))