import sys
import collections
input = sys.stdin.readline

def block(n, m, maze, i, j):
	if i-1 >= 0:
		if maze[i-1][j] == 'G':
			return False
		elif maze[i-1][j] == '.':
			maze[i-1][j] = '#'

	if i+1 < n:
		if maze[i+1][j] == 'G':
			return False
		elif maze[i+1][j] == '.':
			maze[i+1][j] = '#'

	if j-1 >= 0:
		if maze[i][j-1] == 'G':
			return False
		elif maze[i][j-1] == '.':
			maze[i][j-1] = '#'

	if j+1 < m:
		if maze[i][j+1] == 'G':
			return False
		elif maze[i][j+1] == '.':
			maze[i][j+1] = '#'

	return True

def validCell(maze, i, j):
	return i >= 0 and i < len(maze) and j >= 0 and j < len(maze[0]) and maze[i][j] != '#' and maze[i][j] != ','

def countYesG(n, m, maze):
	Q = collections.deque()

	res = 0
	Q.append((n-1, m-1))
	while len(Q) > 0:
		(i, j) = Q.popleft()

		if maze[i][j] == 'G':
			res += 1
		maze[i][j] = ','

		if validCell(maze, i-1, j):
			Q.append((i-1, j))

		if validCell(maze, i+1, j):
			Q.append((i+1, j))

		if validCell(maze, i, j-1):
			Q.append((i, j-1))

		if validCell(maze, i, j+1):
			Q.append((i, j+1))


	return res

def solve(n, m, maze):
	g = 0
	b = 0
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'G':
				g += 1
			elif maze[i][j] == 'B':
				b += 1

	if g == 0 or b == 0:
		return "Yes"

	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'B':
				if block(n, m, maze, i, j):
					continue
				else:
					return "No"

	if maze[n-1][m-1] == '#':
		return "No"

	return "Yes" if countYesG(n, m, maze) == g else "No"

if __name__ == "__main__":
	t = int(input())
	for _ in range(t):
		[n, m] = map(int, input().split())
		maze = []
		for _ in range(n):
			maze.append(list(input().strip()))
		print(solve(n, m, maze))

'''
20 10 100 50
1 1 0 0
20 100 10 50
100 20 10 50
10 20 100 50

10 20,1 100 50
10 50 100 20
10 50 20 100
10 20 50 100
'''