

# from math import factorial as fac
from collections import defaultdict
# from copy import deepcopy
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
# print(f.readline())
sys.setrecursionlimit(10**2)

	
def print_case_iterable(case_num, iterable):
	print("Case #{}: {}".format(case_num," ".join(map(str,iterable))))

def print_case_number(case_num, iterable):
	print("Case #{}: {}".format(case_num,iterable))

def print_iterable(A):
	print (' '.join(A))

def read_int():
	return int(f.readline().strip())
def read_int_array():
	return [int(x) for x in f.readline().strip().split(" ")]
def rns():
	a =  [x for x in f.readline().split(" ")]
	return int(a[0]), a[1].strip()
def read_string():
	return list(f.readline().strip())
def ri():
	return int(f.readline().strip())
def ria():
	return [int(x) for x in f.readline().strip().split(" ")]
def rns():
	a =  [x for x in f.readline().split(" ")]
	return int(a[0]), a[1].strip()
def rs():
	return list(f.readline().strip())
def bi(x):
	return bin(x)[2:]





from collections import deque
import math
NUMBER = 10**9 + 7
# NUMBER = 998244353
def factorial(n) : 
	M = NUMBER
	f = 1
  
	for i in range(1, n + 1):  
		f = (f * i) % M # Now f never can  
						# exceed 10^9+7  
	return f
def mult(a,b):
	return (a * b) % NUMBER

def minus(a , b):
	return (a - b) % NUMBER

def plus(a , b):
	return (a + b) % NUMBER

def egcd(a, b):
	if a == 0:
		return (b, 0, 1)
	else:
		g, y, x = egcd(b % a, a)
		return (g, x - (b // a) * y, y)

def modinv(a):
	m = NUMBER
	g, x, y = egcd(a, m)
	if g != 1:
		raise Exception('modular inverse does not exist')
	else:
		return x % m
def choose(n,k):
	if n < k:
		assert false
	return  mult(factorial(n), modinv(mult(factorial(k),factorial(n-k))))
from collections import deque, defaultdict 
import heapq


def bfs(b,n,m):
	s = set()
	# print('\n'.join(map(str,E.items())))
	ncc = 0 
	# print(b)
	for i in range(n):
		for j in range(m):
			v = (i,j)
			if b[i][j] == '#' or b[i][j] == '.' or v in s:
				continue
			if ncc == 1:
				return False
			q = deque([])
			s.add(v)
			q.append(v)
			# print(v)
			while len(q) > 0:
				k,l = q.popleft()
				# print(i,j)
				# print(s)
				# print(i,j+1, b[i][j+1])
				if k > 0 and b[k-1][l] != '#':
					if (k-1,l) not in s:
						s.add((k-1,l))
						q.append((k-1,l))

				if k < n-1 and b[k+1][l] != '#':
					if (k+1,l) not in s:
						s.add((k+1,l))
						q.append((k+1,l))

				if l > 0 and b[k][l-1] != '#':
					if (k,l-1) not in s:
						s.add((k,l-1))
						q.append((k,l-1))

				if l < m-1 and b[k][l+1] != '#':
					# print('yo')
					if (k,l+1) not in s:
						s.add((k,l+1))
						q.append((k,l+1))
			ncc += 1
	return ncc == 1

def solution(a,n,m):
	# a[n-1][m-1] = 'G'
	b = [['.' for _ in range(m)] for _ in range(n)]
	# print(a)
	seen_g = False
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'G':
				seen_g = True
	if not seen_g:
		return "Yes"
	a[n-1][m-1] = 'G'
	for i in range(n):
		for j in range(m):
			if a[i][j] == '#':
				b[i][j] = '#'
			elif a[i][j] == 'B':
				b[i][j] = '#'
				if i > 0:
					if a[i-1][j] == 'G':
						return "No"
					b[i-1][j] = '#'

				if i < n-1:
					if a[i+1][j] == 'G':
						return "No"
					b[i+1][j] = '#'

				if j > 0:
					if a[i][j-1] == 'G':
						return "No"
					b[i][j-1] = '#'

				if j < m-1:
					if a[i][j+1] == 'G':
						return "No"
					b[i][j+1] = '#'

			elif a[i][j] == 'G':
				seen_g = True
				b[i][j] = 'G'

	return "Yes" if bfs(b,n,m) else "No"


def main():
	T = ri()
	for i in range(T):
		n,m = ria()
		a = []
		for _ in range(n):
			a.append(rs())

		x = solution(a,n,m)
		if 'xrange' not in dir(__builtins__):
			print(x)
		else:
			print >>output,str(x)# "Case #"+str(i+1)+':',
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()

if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
#example usage:
#    for l in res:
#       print >>output, str(len(l)) + ' ' +  ' '.join(l)

if __name__ == '__main__':
	main()

