from sys import stdin,stdout
from math import gcd,sqrt
from collections import deque
input=stdin.readline
R=lambda:map(int,input().split())
I=lambda:int(input())
S=lambda:input().rstrip('\n')
P=lambda x:stdout.write(x)
hg=lambda x,y:((y+x-1)//x)*x
cu=lambda x:max(0,x-1)
cd=lambda x:min(r-1,x+1)
cl=lambda x:max(0,x-1)
cr=lambda x:min(c-1,x+1)
N=10**9+7
for _ in range(I()):
	r,c=R()
	a=[]
	cnt_g=0
	for i in range(r):
		p=list(S())
		cnt_g+=p.count('G')
		a+=p,
	for i in range(r):
		for j in range(c):
			if a[i][j]=='B':
				if a[cu(i)][j]=='.':a[cu(i)][j]='#'
				if a[cd(i)][j]=='.':a[cd(i)][j]='#'
				if a[i][cr(j)]=='.':a[i][cr(j)]='#'
				if a[i][cl(j)]=='.':a[i][cl(j)]='#'
	d={'G':0,'B':0,'.':0}
	v=[[1]*c for i in range(r)]
	stk=[]
	if a[r-1][c-1]!='#':stk+=(r-1,c-1),;v[r-1][c-1]=0;d[a[r-1][c-1]]+=1
	while stk:
		x,y=stk.pop()
		if a[cu(x)][y]!='#' and v[cu(x)][y]:
			stk+=(cu(x),y),
			v[cu(x)][y]=0
			d[a[cu(x)][y]]+=1
		if a[cd(x)][y]!='#' and v[cd(x)][y]:
			stk+=(cd(x),y),
			v[cd(x)][y]=0
			d[a[cd(x)][y]]+=1
		if a[x][cr(y)]!='#' and v[x][cr(y)]:
			stk+=(x,cr(y)),
			v[x][cr(y)]=0
			d[a[x][cr(y)]]+=1
		if a[x][cl(y)]!='#' and v[x][cl(y)]:
			stk+=(x,cl(y)),
			v[x][cl(y)]=0
			d[a[x][cl(y)]]+=1
	if d['G']!=cnt_g or d['B']:print('NO')
	else:print('YES')