import sys
def II():
	return int(sys.stdin.readline())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def MI():
	return map(int, sys.stdin.readline().split())

def SI():
	return sys.stdin.readline().strip()
def BFS(n,m,l):
	visited = []
	for i in range(n+2):
		visited.append([False]*(m+2))
	queue = [[n,m]]
	count = 0
	visited[n][m] = True
	while queue:
		s = queue.pop(0)
		i,j = s[0],s[1]
		if l[i][j] == "G":
			count+=1
		for z in [[i,j+1],[i,j-1],[i+1,j],[i-1,j]]:
			if l[z[0]][z[1]] != "#" and l[z[0]][z[1]]!="B" and visited[z[0]][z[1]] == False:
				queue.append(z[:])
				visited[z[0]][z[1]] = True
	return count
t = II()
for q in range(t):
	n,m = MI()
	l = [["#"]*(m+2)]
	for i in range(n):
		l.append(["#"]+list(SI())+["#"])
	l.append(["#"]*(m+2))
	boo = True
	Gs = 0
	for i in range(1,n+1):
		for j in range(1,m+1):
			if l[i][j] == "B":
				if "G" in [l[i][j-1],l[i][j+1],l[i-1][j],l[i+1][j]]:
					boo = False
					break
				else:
					if l[i][j-1] !="B":
						l[i][j-1] = "#"
					if l[i+1][j] !="B":
						l[i+1][j] = "#"
					if l[i][j+1] !="B":
						l[i][j+1] = "#"
					if l[i-1][j] !="B":
						l[i-1][j] = "#"
			elif l[i][j] == "G":
				Gs+=1
		if boo == False:
			break
	if boo == False:
		print("No")
	else:
		if l[n][m] == "#":
			boo = False
		if not BFS(n,m,l)  == Gs:
				boo = False
		if Gs == 0:
			boo = True
		if boo:
			print("Yes")
		else:
			print("No")
'''
1
4 4
..B.
G...
....
....

'''


