# f = open('test.py')
# def input():
# 	return f.readline().replace('\n','')

# import heapq
# import bisect
# from collections import deque
# from collections import defaultdict
def read_list():
	return list(map(int,input().split(' ')))
def print_list(l):
	print(' '.join(map(str,l)))


N = int(input())
for _ in range(N):
	n, m = read_list()
	mave = []
	flag = True
	g_count = 0
	for _ in range(n):
		mave.append(list(input()))
	# print(mave)
	if mave[-1][-1] == 'B':
		flag = False

	for i in range(n):
		if not flag:
			break
		for j in range(m):
			if mave[i][j]=='B':
				if i>0:
					if mave[i-1][j]=='G':
						flag = False
						break
					if mave[i-1][j]=='.':
						mave[i-1][j] = '#'
				if j>0:
					if mave[i][j-1]=='G':
						flag = False
						break
					if mave[i][j-1]=='.':
						mave[i][j-1] = '#'	
				if i<n-1:
					if mave[i+1][j]=='G':
						flag = False
						break
					if mave[i+1][j]=='.':
						mave[i+1][j] = '#'
				if j<m-1:
					if mave[i][j+1]=='G':
						flag = False
						break
					if mave[i][j+1]=='.':
						mave[i][j+1] = '#'
			elif mave[i][j]=='G':
				g_count+=1

	if mave[-1][-1]=='#' and g_count>0:
		flag = False

	if flag:
		vaild = set()
		vaild.add((n-1,m-1))
		now = [(n-1,m-1)]
		while now and g_count>0:
			x,y = now.pop()
			if mave[x][y] == 'G':
				g_count-=1
			if x>0 and (x-1,y) not in vaild and mave[x-1][y]!='#':
				now.append((x-1,y))
				vaild.add((x-1,y))
			if y>0 and (x,y-1) not in vaild and mave[x][y-1]!='#':
				now.append((x,y-1))
				vaild.add((x,y-1))
			if x<n-1 and (x+1,y) not in vaild and mave[x+1][y]!='#':
				now.append((x+1,y))
				vaild.add((x+1,y))
			if y<m-1 and (x,y+1) not in vaild and mave[x][y+1]!='#':
				now.append((x,y+1))
				vaild.add((x,y+1))
		if g_count>0:
			flag = False
	if flag:
		print('Yes')
	else:
		print('No')