import sys
from math import sqrt, gcd, ceil, log
# from bisect import bisect, bisect_left
from collections import defaultdict, Counter, deque
# from heapq import heapify, heappush, heappop
input = sys.stdin.readline
read = lambda: list(map(int, input().strip().split()))

sys.setrecursionlimit(10**5)

def main():
	ans= []
	def dfs(a, b, cnt):
		if visited[(a, b)]:
			return(0)
		if a < 0 or b < 0 or a == n or b == m:
			return(0)

		visited[(a,b)] = 1

		if arr[a][b] == "#":
			return(0)
		if arr[a][b] == "B":
			return(-100000)

		if arr[a][b] == ".":
			return(dfs(a-1, b, cnt)+dfs(a, b-1, cnt)+dfs(a+1, b, cnt)+dfs(a, b+1, cnt))
		if arr[a][b] == "G":
			return(1 + dfs(a-1, b, cnt)+dfs(a, b-1, cnt)+dfs(a+1, b, cnt)+dfs(a, b+1, cnt))
	for _ in range(int(input())):
		n, m = read(); arr = []; visited = defaultdict(int)
		for i in range(n):arr.append(list(input().strip()))

		for i in range(n):
			for j in range(m):
				visited[(i, j)] = 0

		goods = 0
		for i in range(n):
			for j in range(m):
				if arr[i][j] == "B":
					for child in [(i-1, j), (i+1, j), (i, j+1), (i, j-1)]:
						x, y = child
						if child in visited and arr[x][y] == ".":
							arr[x][y] = "#"
				elif arr[i][j] == "G":goods+=1

		
		
		if dfs(n-1, m-1, 0) == goods:
			ans.append("YES")
		else:
			ans.append("NO")

	print(("\n").join(ans))


if __name__ == "__main__":
	main()