Vivek has encountered a problem. He has a maze that can be represented as an $n \times m$ grid. Each of the grid cells may represent the following:  Empty — '.'  Wall — '#'  Good person  — 'G'  Bad person — 'B' 

The only escape from the maze is at cell $(n, m)$.

A person can move to a cell only if it shares a side with their current cell and does not contain a wall. Vivek wants to block some of the empty cells by replacing them with walls in such a way, that all the good people are able to escape, while none of the bad people are able to. A cell that initially contains 'G' or 'B' cannot be blocked and can be travelled through.

Help him determine if there exists a way to replace some (zero or more) empty cells with walls to satisfy the above conditions.

It is guaranteed that the cell $(n,m)$ is empty. Vivek can also block this cell.


-----Input-----

The first line contains one integer $t$ $(1 \le t \le 100)$ — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers $n$, $m$ $(1 \le n, m \le 50)$ — the number of rows and columns in the maze.

Each of the next $n$ lines contain $m$ characters. They describe the layout of the maze. If a character on a line equals '.', the corresponding cell is empty. If it equals '#', the cell has a wall. 'G' corresponds to a good person and 'B' corresponds to a bad person.


-----Output-----

For each test case, print "Yes" if there exists a way to replace some empty cells with walls to satisfy the given conditions. Otherwise print "No"

You may print every letter in any case (upper or lower).


-----Example-----
Input
6
1 1
.
1 2
G.
2 2
#B
G.
2 3
G.#
B#.
3 3
#B.
#..
GG.
2 2
#B
B.

Output
Yes
Yes
No
No
Yes
Yes



-----Note-----

For the first and second test cases, all conditions are already satisfied.

For the third test case, there is only one empty cell $(2,2)$, and if it is replaced with a wall then the good person at $(1,2)$ will not be able to escape.

For the fourth test case, the good person at $(1,1)$ cannot escape.

For the fifth test case, Vivek can block the cells $(2,3)$ and $(2,2)$.

For the last test case, Vivek can block the destination cell $(2, 2)$.

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Graph algorithms

Graph traversal

Shortest paths

Constructive algorithms

Implementation

Greedy algorithms

Spanning trees


Solutions:
from sys import setrecursionlimit
setrecursionlimit(10 ** 5)

def set_norm(norm, n_i, n_j, n, m):
	if -1 < n_i < n and -1 < n_j < m:
		norm[n_i][n_j] = 1

def gettable(norm, n, m, i, j, used=None):
	if used is None:
		used = set()
	used.add((i, j))
	if i - 1 >= 0 and norm[i - 1][j] == 0 and ((i - 1, j) not in used):
		gettable(norm, n, m, i - 1, j, used)
	if i + 1 < n and norm[i + 1][j] == 0 and ((i + 1, j) not in used):
		gettable(norm, n, m, i + 1, j, used)
	if j - 1 >= 0 and norm[i][j - 1] == 0 and ((i, j - 1) not in used):
		gettable(norm, n, m, i, j - 1, used)
	if j + 1 < m and norm[i][j + 1] == 0 and ((i, j + 1) not in used):
		gettable(norm, n, m, i, j + 1, used)
	return used

def process():
	[n, m] = list(map(int, input().split(' ')))
	a = []
	for i in range(n):
		s = input().strip()
		a.append(s)
	norm = [[0 for j in range(m)] for i in range(n)]
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'B':
				(n_i, n_j) = (i, j)
				set_norm(norm, n_i, n_j, n, m)
				(n_i, n_j) = (i - 1, j)
				set_norm(norm, n_i, n_j, n, m)
				(n_i, n_j) = (i + 1, j)
				set_norm(norm, n_i, n_j, n, m)
				(n_i, n_j) = (i, j - 1)
				set_norm(norm, n_i, n_j, n, m)
				(n_i, n_j) = (i, j + 1)
				set_norm(norm, n_i, n_j, n, m)
			elif a[i][j] == '#':
				norm[i][j] = 1
	goods = []
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'G':
				goods.append((i, j))
	if len(goods) == 0:
		print('Yes')
		return
	if norm[n - 1][m - 1] == 1:
		print('No')
	else:
		reachable = gettable(norm, n, m, n - 1, m - 1)
		for good in goods:
			if good not in reachable:
				print('No')
				return
		print('Yes')
t = int(input())
for _ in range(t):
	process()


from collections import deque
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__
grid = [[0 for x in range(55)] for y in range(55)]
DX = [0, 1, 0, -1]
DY = [1, 0, -1, 0]

def bfs(n, m, badGuy, goodGuy):
	visited = [[0 for x in range(m)] for y in range(n)]
	q = deque([[n - 1, m - 1]])
	visited[n - 1][m - 1] = 1
	while len(q):
		(x, y) = q.popleft()
		if badGuy and grid[x][y] == 'B':
			return 'No'
		if goodGuy and grid[x][y] == 'G':
			grid[x][y] = '.'
		for (dx, dy) in zip(DX, DY):
			if 0 <= x + dx < n and 0 <= y + dy < m:
				if grid[x + dx][y + dy] != '#' and (not visited[x + dx][y + dy]):
					visited[x + dx][y + dy] = True
					q.append([x + dx, y + dy])
	for x in range(n):
		for y in range(m):
			if grid[x][y] == 'G':
				return 'No'
	return 'Yes'

def solve(n, m):
	badGuy = False
	goodGuy = False
	for x in range(n):
		for y in range(m):
			if grid[x][y] == 'B':
				badGuy = True
				for (dx, dy) in zip(DX, DY):
					if 0 <= x + dx < n and 0 <= y + dy < m:
						if grid[x + dx][y + dy] == 'G':
							return 'No'
						if grid[x + dx][y + dy] == '.':
							grid[x + dx][y + dy] = '#'
			if grid[x][y] == 'G':
				goodGuy = True
	if not goodGuy:
		return 'Yes'
	return bfs(n, m, badGuy, goodGuy)
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	for x in range(n):
		temp = input()
		for y in range(m):
			grid[x][y] = temp[y]
	print(solve(n, m))


from collections import deque

def test_case() -> bool:
	(n, m) = map(int, input().split())
	grid = list()
	for i in range(n):
		grid.append(list(input()))
	valid = lambda r, c: r >= 0 and r < n and (c >= 0) and (c < m)
	num_good = 0
	directions = ((-1, 0), (1, 0), (0, -1), (0, 1))
	for r in range(n):
		for c in range(m):
			if grid[r][c] == 'B':
				for (dr, dc) in directions:
					(x, y) = (r + dr, c + dc)
					if not valid(x, y):
						continue
					if grid[x][y] == 'G':
						return False
					if grid[x][y] == '.':
						grid[x][y] = '#'
			elif grid[r][c] == 'G':
				num_good += 1
	if num_good == 0:
		return True
	if grid[-1][-1] == '#':
		return False
	q = deque()
	visited = set()
	q.append((n - 1, m - 1))
	visited.add((n - 1, m - 1))
	while q:
		(r, c) = q.popleft()
		if grid[r][c] == 'G':
			num_good -= 1
		for (dr, dc) in directions:
			(x, y) = (r + dr, c + dc)
			if not valid(x, y) or (x, y) in visited:
				continue
			if grid[x][y] != '#':
				q.append((x, y))
				visited.add((x, y))
	return num_good == 0
t = int(input())
for _ in range(t):
	res = test_case()
	print('yes' if res else 'no')


from sys import stdin, stdout

def main():
	t = int(stdin.readline())
	for _ in range(t):
		(n, m) = list(map(int, stdin.readline().split()))
		mp = []
		for _ in range(n):
			tmp = stdin.readline().strip()
			newer = []
			for x in tmp:
				newer.append(x)
			mp.append(newer)
		cnt = 0
		wrong = False
		for i in range(n):
			for j in range(m):
				if mp[i][j] == 'G':
					cnt += 1
				if mp[i][j] == 'B':
					if i > 0 and mp[i - 1][j] == '.':
						mp[i - 1][j] = '#'
					if j > 0 and mp[i][j - 1] == '.':
						mp[i][j - 1] = '#'
					if i + 1 < n and mp[i + 1][j] == '.':
						mp[i + 1][j] = '#'
					if j + 1 < m and mp[i][j + 1] == '.':
						mp[i][j + 1] = '#'
		stack = []
		stack.append((n - 1, m - 1))
		res = 0
		visited = [[False for _ in range(m)] for _ in range(n)]
		visited[n - 1][m - 1] = True
		if mp[n - 1][m - 1] == '#':
			pass
		else:
			while stack:
				new_stack = set()
				for (x, y) in stack:
					if x > 0 and (not visited[x - 1][y]) and (mp[x - 1][y] != '#'):
						new_stack.add((x - 1, y))
						visited[x - 1][y] = True
						if mp[x - 1][y] == 'G':
							res += 1
						if mp[x - 1][y] == 'B':
							wrong = True
							break
					if y > 0 and (not visited[x][y - 1]) and (mp[x][y - 1] != '#'):
						new_stack.add((x, y - 1))
						visited[x][y - 1] = True
						if mp[x][y - 1] == 'G':
							res += 1
						if mp[x][y - 1] == 'B':
							wrong = True
							break
					if x + 1 < n and (not visited[x + 1][y]) and (mp[x + 1][y] != '#'):
						new_stack.add((x + 1, y))
						visited[x + 1][y] = True
						if mp[x + 1][y] == 'G':
							res += 1
						if mp[x + 1][y] == 'B':
							wrong = True
							break
					if y + 1 < m and (not visited[x][y + 1]) and (mp[x][y + 1] != '#'):
						new_stack.add((x, y + 1))
						visited[x][y + 1] = True
						if mp[x][y + 1] == 'G':
							res += 1
						if mp[x][y + 1] == 'B':
							wrong = True
							break
				stack = list(new_stack)
				if wrong:
					break
		if wrong or res != cnt:
			stdout.write('NO\n')
			continue
		stdout.write('YES\n')
main()


import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
	(n, m) = map(int, input().split())
	MAP = [list(input().strip()) for i in range(n)]
	for i in range(n):
		for j in range(m):
			if MAP[i][j] == 'B':
				if 0 <= i + 1 < n and 0 <= j < m and (MAP[i + 1][j] == '.'):
					MAP[i + 1][j] = '#'
				if 0 <= i - 1 < n and 0 <= j < m and (MAP[i - 1][j] == '.'):
					MAP[i - 1][j] = '#'
				if 0 <= i < n and 0 <= j + 1 < m and (MAP[i][j + 1] == '.'):
					MAP[i][j + 1] = '#'
				if 0 <= i < n and 0 <= j - 1 < m and (MAP[i][j - 1] == '.'):
					MAP[i][j - 1] = '#'
	flag = 1
	if MAP[n - 1][m - 1] == '#':
		Q = []
	else:
		Q = [(n - 1, m - 1)]
	while Q and flag:
		(x, y) = Q.pop()
		for (z, w) in [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]:
			if 0 <= z < n and 0 <= w < m:
				if MAP[z][w] == 'B':
					flag = 0
					break
				elif MAP[z][w] != '#':
					MAP[z][w] = '#'
					Q.append((z, w))
	if flag == 0:
		print('No')
		continue
	else:
		for i in range(n):
			for j in range(m):
				if MAP[i][j] == 'G':
					flag = 0
					break
			if flag == 0:
				break
		if flag:
			print('Yes')
		else:
			print('No')


import math
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class Graph:

	def __init__(self):
		self.graph = defaultdict(list)

	def addEdge(self, u, v):
		self.graph[u].append(v)

	def BFS(self, a):
		visited = [False] * (n * m + 1)
		queue = []
		queue.append(n * m)
		visited[n * m] = True
		while queue:
			s = queue.pop(0)
			for i in self.graph[s]:
				if visited[i] == False:
					queue.append(i)
					visited[i] = True
		for i in range(len(a)):
			if visited[a[i]] == False:
				return False
		return True

def isSafe(i, j, matrix):
	if i >= 0 and i < len(matrix) and (j >= 0) and (j < len(matrix[0])) and (matrix[i][j] != '#'):
		return True
	else:
		return False

def findPath(M):
	N = len(M)
	m = len(M[0])
	g = Graph()
	k = 1
	a = []
	for i in range(N):
		for j in range(m):
			if M[i][j] != '#':
				if isSafe(i, j + 1, M):
					g.addEdge(k, k + 1)
				if isSafe(i, j - 1, M):
					g.addEdge(k, k - 1)
				if isSafe(i + 1, j, M):
					g.addEdge(k, k + m)
				if isSafe(i - 1, j, M):
					g.addEdge(k, k - m)
				if M[i][j] == 'G':
					a.append(k)
			k += 1
	return g.BFS(a)
for i in range(int(input())):
	(n, m) = map(int, input().split())
	matrix = [[0 for i in range(m)] for j in range(n)]
	from collections import defaultdict
	s = []
	c = 0
	f = 0
	c1 = 0
	w = []
	for j in range(n):
		s.append(list(input()))
		c += s[-1].count('G')
	if c == 0:
		print('Yes')
		continue
	for i in range(n):
		for j in range(m):
			if s[i][j] == 'B':
				w.append((i, j))
	for y in w:
		i = y[0]
		j = y[1]
		if i > 0:
			if s[i - 1][j] == 'G':
				f = 1
				break
			s[i - 1][j] = '#'
		if j > 0:
			if s[i][j - 1] == 'G':
				f = 1
				break
			s[i][j - 1] = '#'
		if i < n - 1:
			if s[i + 1][j] == 'G':
				f = 1
				break
			s[i + 1][j] = '#'
		if j < m - 1:
			if s[i][j + 1] == 'G':
				f = 1
				break
			s[i][j + 1] = '#'
	e = []
	if f == 1:
		print('No')
		continue
	elif findPath(s) == True:
		print('Yes')
	else:
		print('No')


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	maze = []
	for j in range(n):
		maze.append(list(input()))
	isReachable = []
	isConsidered = []
	for j in range(n):
		isReachable.append([])
		isConsidered.append([])
		for k in range(m):
			isReachable[j].append(False)
			isConsidered[j].append(False)
	mazeQueue = [(n - 1, m - 1)]
	mazeQueueIndex = 0
	while True:
		if mazeQueueIndex >= len(mazeQueue):
			break
		currentMazeLocation = mazeQueue[mazeQueueIndex]
		mazeQueueIndex += 1
		if isConsidered[currentMazeLocation[0]][currentMazeLocation[1]]:
			continue
		isConsidered[currentMazeLocation[0]][currentMazeLocation[1]] = True
		isCurrentLocationReachable = True
		if maze[currentMazeLocation[0]][currentMazeLocation[1]] == '#':
			isCurrentLocationReachable = False
		if currentMazeLocation[0] > 0 and maze[currentMazeLocation[0] - 1][currentMazeLocation[1]] == 'B':
			isCurrentLocationReachable = False
		if currentMazeLocation[1] > 0 and maze[currentMazeLocation[0]][currentMazeLocation[1] - 1] == 'B':
			isCurrentLocationReachable = False
		if currentMazeLocation[0] < n - 1 and maze[currentMazeLocation[0] + 1][currentMazeLocation[1]] == 'B':
			isCurrentLocationReachable = False
		if currentMazeLocation[1] < m - 1 and maze[currentMazeLocation[0]][currentMazeLocation[1] + 1] == 'B':
			isCurrentLocationReachable = False
		if isCurrentLocationReachable:
			isReachable[currentMazeLocation[0]][currentMazeLocation[1]] = True
			if currentMazeLocation[0] > 0 and isConsidered[currentMazeLocation[0] - 1][currentMazeLocation[1]] == False:
				mazeQueue.append((currentMazeLocation[0] - 1, currentMazeLocation[1]))
			if currentMazeLocation[1] > 0 and isConsidered[currentMazeLocation[0]][currentMazeLocation[1] - 1] == False:
				mazeQueue.append((currentMazeLocation[0], currentMazeLocation[1] - 1))
			if currentMazeLocation[0] < n - 1 and isConsidered[currentMazeLocation[0] + 1][currentMazeLocation[1]] == False:
				mazeQueue.append((currentMazeLocation[0] + 1, currentMazeLocation[1]))
			if currentMazeLocation[1] < m - 1 and isConsidered[currentMazeLocation[0]][currentMazeLocation[1] + 1] == False:
				mazeQueue.append((currentMazeLocation[0], currentMazeLocation[1] + 1))
	isRescuable = True
	for j in range(n):
		for k in range(m):
			if maze[j][k] == 'G' and isReachable[j][k] == False:
				isRescuable = False
	if isRescuable:
		print('Yes')
	else:
		print('No')


import collections
T = int(input())
for t_itr in range(T):
	(N, M) = map(int, input().split())
	A = []
	for _ in range(N):
		A.append(list(input()))
	result = True
	count = 0
	for j in range(N):
		for i in range(M):
			if A[j][i] == 'B':
				if j + 1 < N:
					if A[j + 1][i] == 'G':
						result = False
					if A[j + 1][i] == '.':
						A[j + 1][i] = '#'
				if j - 1 > -1:
					if A[j - 1][i] == 'G':
						result = False
					if A[j - 1][i] == '.':
						A[j - 1][i] = '#'
				if i + 1 < M:
					if A[j][i + 1] == 'G':
						result = False
					if A[j][i + 1] == '.':
						A[j][i + 1] = '#'
				if i - 1 > -1:
					if A[j][i - 1] == 'G':
						result = False
					if A[j][i - 1] == '.':
						A[j][i - 1] = '#'
			if A[j][i] == 'G':
				count += 1
		if not result:
			break
	if A[N - 1][M - 1] == '#' and count > 0:
		result = False
	if result:
		stack = collections.deque()
		visited = set()
		stack.append(M * N - 1)
		found = False
		while stack:
			item = stack.pop()
			(x, y) = divmod(item, M)
			if item not in visited:
				if A[x][y] == 'G':
					count -= 1
				if count == 0:
					break
				visited.add(item)
				if x + 1 < N:
					if A[x + 1][y] == '.' or A[x + 1][y] == 'G':
						stack.append((x + 1) * M + y)
				if x - 1 > -1:
					if A[x - 1][y] == '.' or A[x - 1][y] == 'G':
						stack.append((x - 1) * M + y)
				if y + 1 < M:
					if A[x][y + 1] == '.' or A[x][y + 1] == 'G':
						stack.append(x * M + y + 1)
				if y - 1 > -1:
					if A[x][y - 1] == '.' or A[x][y - 1] == 'G':
						stack.append(x * M + y - 1)
		if count > 0:
			result = False
	if result:
		print('Yes')
	else:
		print('No')


from sys import stdin, stdout
from collections import deque

def main():
	for _ in range(int(stdin.readline())):
		(n, m) = map(int, stdin.readline().split())
		matrix = []
		for i in range(n):
			matrix.append(list(stdin.readline().strip()))
		counter = 0
		g = 0
		for i in range(n):
			for j in range(m):
				if matrix[i][j] == 'B':
					if j - 1 >= 0:
						if matrix[i][j - 1] == '.':
							matrix[i][j - 1] = '#'
						if matrix[i][j - 1] == 'G':
							counter = 1
							break
					if j + 1 < m:
						if matrix[i][j + 1] == '.':
							matrix[i][j + 1] = '#'
						if matrix[i][j + 1] == 'G':
							counter = 1
							break
					if i - 1 >= 0:
						if matrix[i - 1][j] == '.':
							matrix[i - 1][j] = '#'
						if matrix[i - 1][j] == 'G':
							counter = 1
							break
					if i + 1 < n:
						if matrix[i + 1][j] == '.':
							matrix[i + 1][j] = '#'
						if matrix[i + 1][j] == 'G':
							counter = 1
							break
				if matrix[i][j] == 'G':
					g += 1
			if counter == 1:
				break
		if counter == 1:
			print('No')
		elif g == 0:
			print('Yes')
		else:
			visited = []
			for i in range(n):
				lis = [0 for j in range(m)]
				visited.append(lis)
			flag = 0
			if matrix[n - 1][m - 1] == '#' or matrix[n - 1][m - 1] == 'B':
				print('No')
				continue
			qu = deque()
			qu.append((n - 1, m - 1))
			visited[n - 1][m - 1] = 1
			while qu:
				el = qu.popleft()
				if el[1] - 1 >= 0 and visited[el[0]][el[1] - 1] == 0:
					if matrix[el[0]][el[1] - 1] == '.' or matrix[el[0]][el[1] - 1] == 'G':
						qu.append((el[0], el[1] - 1))
						visited[el[0]][el[1] - 1] = 1
				if el[1] + 1 < m and visited[el[0]][el[1] + 1] == 0:
					if matrix[el[0]][el[1] + 1] == '.' or matrix[el[0]][el[1] + 1] == 'G':
						qu.append((el[0], el[1] + 1))
						visited[el[0]][el[1] + 1] = 1
				if el[0] - 1 >= 0 and visited[el[0] - 1][el[1]] == 0:
					if matrix[el[0] - 1][el[1]] == '.' or matrix[el[0] - 1][el[1]] == 'G':
						qu.append((el[0] - 1, el[1]))
						visited[el[0] - 1][el[1]] = 1
				if el[0] + 1 < n and visited[el[0] + 1][el[1]] == 0:
					if matrix[el[0] + 1][el[1]] == '.' or matrix[el[0] + 1][el[1]] == 'G':
						qu.append((el[0] + 1, el[1]))
						visited[el[0] + 1][el[1]] = 1
			for i in range(n):
				for j in range(m):
					if matrix[i][j] == 'G' and visited[i][j] == 0:
						flag = 1
						break
			if flag:
				print('No')
			else:
				print('Yes')
main()


import sys
import string
input = sys.stdin.readline
import math
from operator import xor
p = 10 ** 9 + 7
n = int(input())
for i in range(n):
	(a, b) = list(map(int, input().split()))
	ll = []
	good_count = 0
	for x in range(a):
		r = list(input().rstrip())
		good_count += r.count('G')
		ll.append(r)
	ok = 1
	for x in range(a):
		for y in range(b):
			if x + 1 < a:
				if 'G' == ll[x][y] and 'B' == ll[x + 1][y]:
					ok = 0
				if 'B' == ll[x][y] and 'G' == ll[x + 1][y]:
					ok = 0
			if y + 1 < b:
				if 'G' == ll[x][y] and 'B' == ll[x][y + 1]:
					ok = 0
				if 'B' == ll[x][y] and 'G' == ll[x][y + 1]:
					ok = 0
	if ok == 0:
		print('no')
	for x in range(a):
		for y in range(b):
			if ll[x][y] == 'B':
				if x + 1 < a and ll[x + 1][y] == '.':
					ll[x + 1][y] = '#'
				if x - 1 > -1 and ll[x - 1][y] == '.':
					ll[x - 1][y] = '#'
				if y + 1 < b and ll[x][y + 1] == '.':
					ll[x][y + 1] = '#'
				if y - 1 > -1 and ll[x][y - 1] == '.':
					ll[x][y - 1] = '#'
	if ok == 1:
		if ll[a - 1][b - 1] != '#':
			explored = [(a - 1, b - 1)]
		else:
			explored = []
		all_explored = set()
		visited = set()
		xc = len(all_explored)
		for j in range(a * b + 5):
			all_explored.update(set(explored))
			if len(all_explored) == xc:
				break
			xc = len(all_explored)
			new_explored = []
			for node in explored:
				(x, y) = node
				if (x, y) not in visited:
					if x + 1 < a and ll[x + 1][y] != '#':
						new_explored.append((x + 1, y))
					if x - 1 > -1 and ll[x - 1][y] != '#':
						new_explored.append((x - 1, y))
					if y + 1 < b and ll[x][y + 1] != '#':
						new_explored.append((x, y + 1))
					if y - 1 > -1 and ll[x][y - 1] != '#':
						new_explored.append((x, y - 1))
				visited.add((x, y))
			explored = new_explored
		count = 0
		for node in list(all_explored):
			if ll[node[0]][node[1]] == 'G':
				count += 1
		if count == good_count or good_count == 0:
			print('yes')
		else:
			print('no')


import sys
from collections import deque
readline = sys.stdin.readline
ns = lambda : readline().rstrip()
ni = lambda : int(readline().rstrip())
nm = lambda : map(int, readline().split())
nl = lambda : list(map(int, readline().split()))

def solve():
	(h, w) = nm()
	g = [list(ns()) for _ in range(h)]
	d = [(1, 0), (0, 1), (-1, 0), (0, -1)]
	for i in range(h):
		for j in range(w):
			if g[i][j] == 'B':
				for (di, dj) in d:
					ni = i + di
					nj = j + dj
					if 0 <= ni < h and 0 <= nj < w and (g[ni][nj] == '.'):
						g[ni][nj] = '#'
	q = deque()
	f = [[-1] * w for _ in range(h)]
	if g[-1][-1] == '.':
		f[-1][-1] = 0
		q.append((h - 1, w - 1))
	while q:
		(i, j) = q.popleft()
		for (di, dj) in d:
			ni = i + di
			nj = j + dj
			if 0 <= ni < h and 0 <= nj < w and (g[ni][nj] != '#') and (f[ni][nj] < 0):
				f[ni][nj] = f[i][j] + 1
				q.append((ni, nj))
	for i in range(h):
		for j in range(w):
			if g[i][j] == 'G' and f[i][j] < 0 or (g[i][j] == 'B' and f[i][j] >= 0):
				print('No')
				return
	print('Yes')
	return
T = int(input())
for _ in range(T):
	solve()


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	arr = []
	nArr = []
	for i in range(n):
		arr.append(list(input()))
	for i in range(n):
		strQ = []
		for g in range(m):
			strQ.append(arr[i][g])
		nArr.append(strQ)
	fl = True
	for i in range(n):
		for g in range(m):
			if arr[i][g] == 'B':
				if arr[max(i - 1, 0)][g] == 'G' or arr[min(i + 1, n - 1)][g] == 'G' or arr[i][min(g + 1, m - 1)] == 'G' or (arr[i][max(g - 1, 0)] == 'G'):
					fl = False
					break
				else:
					nArr[max(i - 1, 0)][g] = '#'
					nArr[min(i + 1, n - 1)][g] = '#'
					nArr[i][min(g + 1, m - 1)] = '#'
					nArr[i][max(g - 1, 0)] = '#'
		else:
			continue
		break
	if fl:
		arr = nArr
		g = 0
		for i in range(n):
			g += arr[i].count('G')
		if g and arr[n - 1][m - 1] == '#':
			print('No')
			continue
		if not g:
			print('Yes')
			continue
		was = []
		for i in range(n):
			was.append([False] * m)

		def fillPath(x, y):
			if not was[y][x]:
				was[y][x] = True
				if not was[max(y - 1, 0)][x] and arr[max(y - 1, 0)][x] != '#':
					fillPath(x, max(y - 1, 0))
				if not was[min(y + 1, n - 1)][x] and arr[min(y + 1, n - 1)][x] != '#':
					fillPath(x, min(y + 1, n - 1))
				if not was[y][min(x + 1, m - 1)] and arr[y][min(x + 1, m - 1)] != '#':
					fillPath(min(x + 1, m - 1), y)
				if not was[y][max(x - 1, 0)] and arr[y][max(x - 1, 0)] != '#':
					fillPath(max(x - 1, 0), y)
		fillPath(m - 1, n - 1)
		for i in range(n):
			for g in range(m):
				if arr[i][g] == 'G' and (not was[i][g]):
					print('No')
					break
			else:
				continue
			break
		else:
			print('Yes')
	else:
		print('No')


import bisect
import collections
import copy
import functools
import heapq
import itertools
import math
import random
import re
import sys
import time
import string
from typing import *
sys.setrecursionlimit(99999)
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		arr.append(list(input()))
	win = True
	vis = set()
	tree = list(range(n * m))

	def find(x):
		if tree[x] != x:
			tree[x] = find(tree[x])
		return tree[x]

	def connect(s, e):
		tree[find(s)] = find(e)
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'B':
				for (nx, ny) in [(i - 1, j), (i + 1, j), (i, j + 1), (i, j - 1)]:
					if 0 <= nx < n and 0 <= ny < m:
						if arr[nx][ny] == 'G':
							win = False
						elif arr[nx][ny] == '.':
							arr[nx][ny] = '#'
	if win == False:
		print('NO')
	else:
		for i in range(n):
			for j in range(m):
				if arr[i][j] in '.G':
					if i > 0 and arr[i - 1][j] in '.G':
						connect(i * m + j, (i - 1) * m + j)
					if j > 0 and arr[i][j - 1] in '.G':
						connect(i * m + j, i * m + j - 1)
		for i in range(n):
			for j in range(m):
				if arr[i][j] == 'G':
					if find(i * m + j) != find(n * m - 1):
						win = False
		if win == False:
			print('NO')
		else:
			print('YES')


from collections import defaultdict
import sys, math
f = None
try:
	f = open('q1.input', 'r')
except IOError:
	f = sys.stdin
if 'xrange' in dir(__builtins__):
	range = xrange
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

def factorial(n):
	M = NUMBER
	f = 1
	for i in range(1, n + 1):
		f = f * i % M
	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()
	ncc = 0
	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)
			while len(q) > 0:
				(k, l) = q.popleft()
				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] != '#':
					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):
	b = [['.' for _ in range(m)] for _ in range(n)]
	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))
	if 'xrange' in dir(__builtins__):
		print(output.getvalue())
		output.close()
if 'xrange' in dir(__builtins__):
	import cStringIO
	output = cStringIO.StringIO()
main()


import bisect
import decimal
from decimal import Decimal
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
decimal.getcontext().prec = 46

def primeFactors(n):
	prime = set()
	while n % 2 == 0:
		prime.add(2)
		n = n // 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			prime.add(i)
			n = n // i
	if n > 2:
		prime.add(n)
	return list(prime)

def getFactors(n):
	factors = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				factors.append(i)
			else:
				factors.append(i)
				factors.append(n // i)
		i = i + 1
	return factors

def SieveOfEratosthenes(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	num = []
	for p in range(2, n + 1):
		if prime[p]:
			num.append(p)
	return num

def lcm(a, b):
	return a * b // math.gcd(a, b)

def sort_dict(key_value):
	return sorted(key_value.items(), key=lambda kv: (kv[1], kv[0]))

def list_input():
	return list(map(int, input().split()))

def num_input():
	return map(int, input().split())

def string_list():
	return list(input())

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def binaryToDecimal(n):
	return int(n, 2)

def DFS(n, s, adj):
	visited = [False for i in range(n)]
	stack = []
	stack.append(s)
	while len(stack):
		s = stack[-1]
		stack.pop()
		if not visited[s]:
			visited[s] = True
		for node in adj[s]:
			if not visited[node]:
				stack.append(node)

def BFS(mat, n, m, count):
	visited = {}
	queue = []
	c = 0
	queue.append((n, m))
	visited[n, m] = True
	while queue != []:
		(i, j) = queue.pop(0)
		if mat[i][j] == 'G':
			c += 1
			if c == count:
				return c
		if mat[i + 1][j] != '#' and mat[i + 1][j] != 'B':
			try:
				visited[i + 1, j]
			except KeyError:
				queue.append((i + 1, j))
				visited[i + 1, j] = True
		if mat[i - 1][j] != '#' and mat[i - 1][j] != 'B':
			try:
				visited[i - 1, j]
			except KeyError:
				queue.append((i - 1, j))
				visited[i - 1, j] = True
		if mat[i][j - 1] != '#' and mat[i][j - 1] != 'B':
			try:
				visited[i, j - 1]
			except KeyError:
				queue.append((i, j - 1))
				visited[i, j - 1] = True
		if mat[i][j + 1] != '#' and mat[i][j + 1] != 'B':
			try:
				visited[i, j + 1]
			except KeyError:
				queue.append((i, j + 1))
				visited[i, j + 1] = True
	return c

def solve():
	(n, m) = num_input()
	mat = [['#'] * (m + 2)]
	for _ in range(n):
		t = '#' + input() + '#'
		mat.append(list(t))
	mat.append(['#'] * (m + 2))
	flag = False
	count = 0
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if mat[i][j] == 'B':
				if mat[i - 1][j] == 'G' or mat[i + 1][j] == 'G' or mat[i][j - 1] == 'G' or (mat[i][j + 1] == 'G'):
					print('No')
					return
				if mat[i - 1][j] == '.':
					mat[i - 1][j] = '#'
				if mat[i + 1][j] == '.':
					mat[i + 1][j] = '#'
				if mat[i][j - 1] == '.':
					mat[i][j - 1] = '#'
				if mat[i][j + 1] == '.':
					mat[i][j + 1] = '#'
			elif mat[i][j] == 'G':
				flag = True
				count += 1
	if not flag:
		print('Yes')
		return
	elif mat[n][m - 1] == 'B' or mat[n - 1][m] == 'B':
		print('No')
		return
	if count == BFS(mat, n, m, count):
		print('Yes')
	else:
		print('No')
t = int(input())
for _ in range(t):
	solve()


import sys
sys.setrecursionlimit(10 ** 6)

def dfs(i, j, visited, s):
	if (i, j) not in visited:
		visited.add((i, j))
		if (i - 1, j) not in s:
			if i - 1 >= 0:
				dfs(i - 1, j, visited, s)
		if (i + 1, j) not in s:
			if i + 1 <= n:
				dfs(i + 1, j, visited, s)
		if (i, j - 1) not in s:
			if j - 1 >= 0:
				dfs(i, j - 1, visited, s)
		if (i, j + 1) not in s:
			if j + 1 <= m:
				dfs(i, j + 1, visited, s)
	return
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = set()
	b = set()
	g = set()
	h = set()
	i = 0
	f = 0
	while i < n:
		j = 0
		q = input()
		while j < m:
			x = q[j]
			if x == '#':
				s.add((i, j))
			if x == 'G':
				g.add((i, j))
				f = 1
			if x == 'B':
				b.add((i, j))
			if x == '.':
				h.add((i, j))
			j = j + 1
		i = i + 1
	n = n - 1
	m = m - 1
	g.add((n, m))
	if f == 0:
		print('Yes')
		continue
	else:
		f = 0
		for k in b:
			e11 = k[0]
			e12 = k[1] + 1
			e21 = k[0]
			e22 = k[1] - 1
			e31 = k[0] + 1
			e32 = k[1]
			e41 = k[0] - 1
			e42 = k[1]
			if (e11, e12) in g:
				f = 1
				break
			if (e11, e12) in h:
				s.add((e11, e12))
			if (e21, e22) in g:
				f = 1
				break
			if (e21, e22) in h:
				s.add((e21, e22))
			if (e31, e32) in g:
				f = 1
				break
			if (e31, e32) in h:
				s.add((e31, e32))
			if (e41, e42) in g:
				f = 1
				break
			if (e41, e42) in h:
				s.add((e41, e42))
		if f == 1:
			print('No')
			continue
		r = 1
		g.remove((n, m))
		u = set()
		dfs(n, m, u, s)
		for i in g:
			if (i[0], i[1]) not in u:
				r = 0
				break
		if r == 0:
			print('No')
		else:
			print('Yes')


import io
import os
from collections import Counter, defaultdict, deque
drdc = [(-1, 0), (0, -1), (0, 1), (1, 0)]

def solve(R, C, grid):
	goodCount = 0
	for r in range(R):
		for c in range(C):
			if grid[r][c] == 'G':
				goodCount += 1
			if grid[r][c] == 'B':
				for (dr, dc) in drdc:
					nr = r + dr
					nc = c + dc
					if 0 <= nr < R and 0 <= nc < C:
						if grid[nr][nc] == 'G':
							return 'No'
						if grid[nr][nc] == 'B':
							continue
						assert grid[nr][nc] in '.#'
						grid[nr][nc] = '#'
	if grid[R - 1][C - 1] == '#':
		if goodCount == 0:
			return 'Yes'
		return 'No'
	q = deque([(R - 1, C - 1)])
	seen = set([(R - 1, C - 1)])
	badCount = 0
	while q:
		(r, c) = q.popleft()
		if grid[r][c] == 'G':
			goodCount -= 1
		if grid[r][c] == 'B':
			badCount += 1
		for (dr, dc) in drdc:
			nr = r + dr
			nc = c + dc
			if 0 <= nr < R and 0 <= nc < C and ((nr, nc) not in seen):
				if grid[nr][nc] != '#':
					q.append((nr, nc))
					seen.add((nr, nc))
	if goodCount == 0 and badCount == 0:
		return 'Yes'
	return 'No'
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N, M) = [int(x) for x in input().split()]
	grid = [list(input().decode().rstrip()) for i in range(N)]
	ans = solve(N, M, grid)
	print(ans)


from sys import *
t = int(input())
idir = [1, 0, -1, 0]
jdir = [0, 1, 0, -1]

def solve():
	(h, w) = map(int, input().split())
	mat = [input() for _ in range(h)]
	hasg = 0
	for r in mat:
		for ch in r:
			if ch == 'G':
				hasg = 1
				break
		if hasg:
			break
	if hasg == 0:
		print('Yes')
		return
	fail = 0
	blocked = set()
	for i in range(h):
		for j in range(w):
			if mat[i][j] == 'B':
				for k in range(4):
					ni = i + idir[k]
					nj = j + jdir[k]
					if ni < 0 or ni >= h or nj < 0 or (nj >= w) or (mat[ni][nj] == 'B'):
						continue
					if mat[ni][nj] == 'G':
						fail = 1
						break
					blocked.add((ni, nj))
			if fail:
				break
		if fail:
			break
	reach = [[0 for _ in range(w)] for _ in range(h)]
	q = []
	if not (h - 1, w - 1) in blocked:
		q.append((h - 1, w - 1))
		reach[h - 1][w - 1] = 1
	front = 0
	while front < len(q):
		(i, j) = q[front]
		front += 1
		for k in range(4):
			ni = i + idir[k]
			nj = j + jdir[k]
			if ni < 0 or ni >= h or nj < 0 or (nj >= w) or (mat[ni][nj] == '#') or reach[ni][nj] or ((ni, nj) in blocked):
				continue
			q.append((ni, nj))
			reach[ni][nj] = 1
	for i in range(h):
		for j in range(w):
			if mat[i][j] == 'G' and reach[i][j] == 0:
				fail = 1
				break
		if fail:
			break
	if fail:
		print('No')
	else:
		print('Yes')
for _ in range(t):
	solve()


import sys
input = sys.stdin.readline

def solve():
	(N, M) = map(int, input().split())
	a = [list(input())[:-1] for _ in range(N)]
	d = [-1, 0, 1, 0]
	for i in range(N):
		for j in range(M):
			if a[i][j] == 'B':
				for k in range(4):
					y = i + d[k]
					x = j + d[-1 - k]
					if y in range(N) and x in range(M):
						if a[y][x] == 'G':
							return False
						if a[y][x] == '.':
							a[y][x] = '#'
	vis = [0] * (N * M)
	s = [N * M - 1]
	if a[-1][-1] == '.':
		vis[-1] = 1
		while len(s):
			p = s.pop()
			i = p // M
			j = p % M
			for k in range(4):
				y = i + d[k]
				x = j + d[-1 - k]
				q = y * M + x
				if y in range(N) and x in range(M):
					if a[y][x] == '#':
						continue
					if vis[q]:
						continue
					vis[q] = 1
					s.append(q)
	for i in range(N):
		for j in range(M):
			if a[i][j] == 'G' and vis[i * M + j] == 0:
				return False
	return True
for _ in range(int(input())):
	if solve():
		print('Yes')
	else:
		print('No')


import sys
sys.setrecursionlimit(10 ** 9)
t = int(input())

def dfs(N):
	global visited
	global d
	global m
	global n
	a = N % m
	b = N // m
	while (b + 1) * m <= N:
		b += 1
	if d[b][a] == '#':
		return 0
	if N in visited:
		return 0
	visited.add(N)
	value = 0
	if d[b][a] == 'G':
		value += 1
	if N % m > 0:
		value += dfs(N - 1)
	if N % m < m - 1:
		value += dfs(N + 1)
	if N < (n - 1) * m:
		value += dfs(N + m)
	if N >= m:
		value += dfs(N - m)
	return value
for _ in range(t):
	(n, m) = map(int, input().split())
	d = []
	for i in range(n):
		s = input()
		d.append([])
		for j in s:
			d[-1].append(j)
	failflag = 0
	gcount = 0
	for i in range(n):
		for j in range(m):
			if d[i][j] == 'B':
				if i > 0 and d[i - 1][j] == '.':
					d[i - 1][j] = '#'
				if i > 0 and d[i - 1][j] == 'G':
					failflag = 1
				if i < n - 1 and d[i + 1][j] == '.':
					d[i + 1][j] = '#'
				if i < n - 1 and d[i + 1][j] == 'G':
					failflag = 1
				if j > 0 and d[i][j - 1] == '.':
					d[i][j - 1] = '#'
				if j > 0 and d[i][j - 1] == 'G':
					failflag = 1
				if j < m - 1 and d[i][j + 1] == '.':
					d[i][j + 1] = '#'
				if j < m - 1 and d[i][j + 1] == 'G':
					failflag = 1
			if d[i][j] == 'G':
				gcount += 1
	visited = set()
	if d[n - 1][m - 1] == 'B':
		failflag = 1
	if failflag == 1:
		print('No')
		continue
	count2 = dfs(n * m - 1)
	if gcount == count2:
		print('Yes')
	else:
		print('No')


import sys
import math
sys.setrecursionlimit(1000000)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')
p2S = lambda x: print(*x, sep=' ')

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

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
Canlevel = True
Gnum = 0

def check(s, tag, ns, ms, n, m, f='None'):
	if n < 0 or n >= ns or m < 0 or (m >= ms):
		return
	elif s[n][m] == 1 or tag[n][m] == True:
		return
	elif s[n][m] == 0:
		s[n][m] = 1
		tag[n][m] = True
	elif s[n][m] == 3:
		tag[n][m] = True
		if f != 'Up':
			check(s, tag, ns, ms, n + 1, m, 'Down')
		if f != 'Down':
			check(s, tag, ns, ms, n - 1, m, 'Up')
		if f != 'Right':
			check(s, tag, ns, ms, n, m + 1, 'Left')
		if f != 'Left':
			check(s, tag, ns, ms, n, m - 1, 'Right')
	elif s[n][m] == 2:
		tag[n][m] = True
		global Canlevel
		Canlevel = False
		return

def level(s, t, ns, ms, n, m, f='None'):
	if n < 0 or n >= ns or m < 0 or (m >= ms):
		return
	elif s[n][m] == 1 or t[n][m] == True:
		return
	elif s[n][m] == 3:
		global Canlevel
		Canlevel = False
		return
	elif s[n][m] == 0 or s[n][m] == 2:
		t[n][m] = True
		if s[n][m] == 2:
			global Gnum
			Gnum += 1
		if f != 'Up':
			level(s, t, ns, ms, n + 1, m, 'Down')
		if f != 'Down':
			level(s, t, ns, ms, n - 1, m, 'Up')
		if f != 'Right':
			level(s, t, ns, ms, n, m + 1, 'Left')
		if f != 'Left':
			level(s, t, ns, ms, n, m - 1, 'Right')

def main():
	_v_ = II()
	for __ in range(_v_):
		global Canlevel, Gnum
		Canlevel = True
		Gnum = 0
		allG = 0
		(n, m) = MI()
		s = []
		sn = []
		tag = []
		taglevel = []
		for i in range(n):
			s.append(SI())
			tag.append([])
			taglevel.append([])
			for j in range(m):
				tag[i].append(False)
				taglevel[i].append(False)
		for i in range(n):
			sn.append([])
			for j in range(m):
				if s[i][j] == '.':
					sn[i].append(0)
				if s[i][j] == '#':
					sn[i].append(1)
				if s[i][j] == 'G':
					sn[i].append(2)
					allG += 1
				if s[i][j] == 'B':
					sn[i].append(3)
		for i in range(n):
			for j in range(m):
				if sn[i][j] == 3 and tag[i][j] == False:
					check(sn, tag, n, m, i, j)
		level(sn, taglevel, n, m, n - 1, m - 1)
		if Canlevel == False:
			print('No')
		elif Gnum == allG:
			print('Yes')
		else:
			print('No')
main()


import sys
input = sys.stdin.readline
t = int(input())
ans = []
for _ in range(t):
	(h, w) = map(int, input().split())
	grid = [list(input()) for _ in range(h)]
	good = set()
	bad = set()
	delta = [(-1, 0), (1, 0), (0, 1), (0, -1)]
	for i in range(h):
		for j in range(w):
			if grid[i][j] == 'G':
				good.add((i, j))
			elif grid[i][j] == 'B':
				bad.add((i, j))
	if not good:
		ans.append('Yes')
		continue
	flg = 0
	for (ci, cj) in bad:
		for (di, dj) in delta:
			(ni, nj) = (ci + di, cj + dj)
			if 0 <= ni < h and 0 <= nj < w:
				if grid[ni][nj] == '.':
					grid[ni][nj] = '#'
				elif grid[ni][nj] == 'G':
					flg = 1
					break
		if flg:
			break
	if flg or grid[h - 1][w - 1] == '#':
		ans.append('No')
		continue
	q = [(h - 1, w - 1)]
	vis = [[0] * w for _ in range(h)]
	vis[-1][-1] = 1
	while q:
		(ci, cj) = q.pop()
		for (di, dj) in delta:
			(ni, nj) = (ci + di, cj + dj)
			if 0 <= ni < h and 0 <= nj < w and (grid[ni][nj] != '#') and (not vis[ni][nj]):
				vis[ni][nj] = 1
				q.append((ni, nj))
	if all((vis[i][j] for (i, j) in good)):
		ans.append('Yes')
	else:
		ans.append('No')
print('\n'.join(ans))


def main():
	import sys
	input = sys.stdin.readline
	sys.setrecursionlimit(10 ** 6)
	t = int(input())
	for _ in range(t):
		(N, M) = [int(x) for x in input().strip().split()]
		g = [0] * N
		for n in range(N):
			g[n] = list(input().strip())
		if g[N - 1][M - 1] == '#' or g[N - 1][M - 1] == 'B':
			print('No')
			continue

		def killBadBoys(n, m):
			q = [(n, m)]
			g[n][m] = '#'
			while q:
				(n, m) = q.pop()
				if n - 1 >= 0:
					if g[n - 1][m] == '.':
						g[n - 1][m] = '#'
					elif g[n - 1][m] == 'B':
						g[n - 1][m] = '#'
						q.append((n - 1, m))
					elif g[n - 1][m] == 'G':
						return False
				if m - 1 >= 0:
					if g[n][m - 1] == '.':
						g[n][m - 1] = '#'
					elif g[n][m - 1] == 'B':
						g[n][m - 1] = '#'
						q.append((n, m - 1))
					elif g[n][m - 1] == 'G':
						return False
				if n + 1 < N:
					if g[n + 1][m] == '.':
						g[n + 1][m] = '#'
					elif g[n + 1][m] == 'B':
						g[n + 1][m] = '#'
						q.append((n + 1, m))
					elif g[n + 1][m] == 'G':
						return False
				if m + 1 < M:
					if g[n][m + 1] == '.':
						g[n][m + 1] = '#'
					elif g[n][m + 1] == 'B':
						g[n][m + 1] = '#'
						q.append((n, m + 1))
					elif g[n][m + 1] == 'G':
						return False
			else:
				return True
		for n in range(N):
			f = True
			for m in range(M):
				if g[n][m] == 'B':
					if killBadBoys(n, m):
						continue
					else:
						f = False
						break
			if not f:
				break
		if not f:
			print('No')
			continue
		if g[N - 1][M - 1] == '.':
			q = [(N - 1, M - 1)]
			g[N - 1][M - 1] = '#'
		else:
			q = []
		while q:
			(n, m) = q.pop()
			if n - 1 >= 0:
				if g[n - 1][m] == '.':
					g[n - 1][m] = '#'
					q.append((n - 1, m))
				elif g[n - 1][m] == 'G':
					g[n - 1][m] = '#'
					q.append((n - 1, m))
			if m - 1 >= 0:
				if g[n][m - 1] == '.':
					g[n][m - 1] = '#'
					q.append((n, m - 1))
				elif g[n][m - 1] == 'G':
					g[n][m - 1] = '#'
					q.append((n, m - 1))
			if n + 1 < N:
				if g[n + 1][m] == '.':
					g[n + 1][m] = '#'
					q.append((n + 1, m))
				elif g[n + 1][m] == 'G':
					g[n + 1][m] = '#'
					q.append((n + 1, m))
			if m + 1 < M:
				if g[n][m + 1] == '.':
					g[n][m + 1] = '#'
					q.append((n, m + 1))
				elif g[n][m + 1] == 'G':
					g[n][m + 1] = '#'
					q.append((n, m + 1))
		f = True
		for n in range(N):
			for m in range(M):
				if g[n][m] == 'B' or g[n][m] == 'G':
					f = False
					break
			if not f:
				break
		else:
			print('Yes')
			continue
		print('No')
main()


import sys
input = sys.stdin.readline

def get_from_maze(maze, pos):
	if pos[0] < 0 or pos[0] >= len(maze) or pos[1] < 0 or (pos[1] >= len(maze[0])):
		return None
	return maze[pos[0]][pos[1]]

def is_poss(n, m):
	maze = []
	bad_guys = set()
	good_guys = set()
	deltas = [(0, 1), (1, 0), (0, -1), (-1, 0)]
	for r in range(n):
		row = list(input())
		maze.append(row)
		for (c, el) in enumerate(row):
			pos = (r, c)
			if el == 'G':
				good_guys.add(pos)
			elif el == 'B':
				bad_guys.add(pos)
	for bgp in bad_guys:
		for delta in deltas:
			new_pos = (bgp[0] + delta[0], bgp[1] + delta[1])
			currently_there = get_from_maze(maze, new_pos)
			if currently_there == '.':
				maze[new_pos[0]][new_pos[1]] = '#'
			elif currently_there == 'G':
				return False
	to_do = [(n - 1, m - 1)]
	done = set()
	entrance = get_from_maze(maze, to_do[0])
	if entrance == '#':
		return len(good_guys) == 0
	elif entrance == 'B':
		return False
	elif entrance == 'G':
		good_guys.remove(to_do[0])
	while len(good_guys) > 0 and len(to_do) > 0:
		pos = to_do.pop(0)
		for delta in deltas:
			new_pos = (pos[0] + delta[0], pos[1] + delta[1])
			if new_pos in done:
				continue
			done.add(new_pos)
			there = get_from_maze(maze, new_pos)
			if there == '.':
				to_do.append(new_pos)
			elif there == 'G':
				to_do.append(new_pos)
				if new_pos in good_guys:
					good_guys.remove(new_pos)
		done.add(pos)
	return len(good_guys) == 0

def main():
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, input().split())
		if is_poss(n, m):
			print('YES')
		else:
			print('NO')
main()


from math import ceil

def lcm(a, b):
	return a * b // gcd(a, b)

def inin():
	return int(input())

def inar():
	return list(map(int, input().split()))

def ar(element, size):
	return [element for i in range(size)]

def yes():
	print('Yes')

def no():
	print('No')
dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]

def dfs(i, j, visited):
	visited[i][j] = True
	for delta in range(4):
		x = j + dx[delta]
		y = i + dy[delta]
		if x >= 0 and y >= 0 and (x < m) and (y < n) and (visited[y][x] == False):
			if maze[y][x] == '.' or maze[y][x] == 'G':
				dfs(y, x, visited)
Gloc = []
Testcase = inin()
for _ in range(Testcase):
	Gloc = []
	(n, m) = inar()
	maze = ['' for i in range(n)]
	for i in range(n):
		maze[i] = list(input())
	pasapasi = False
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'G':
				Gloc.append((i, j))
			if maze[i][j] == 'B':
				for delta in range(4):
					x = j + dx[delta]
					y = i + dy[delta]
					if x >= 0 and y >= 0 and (x < m) and (y < n):
						if maze[y][x] == 'G':
							pasapasi = True
							break
						if maze[y][x] == '.':
							maze[y][x] = '#'
	if pasapasi:
		no()
	elif maze[n - 1][m - 1] == '#':
		if Gloc == []:
			yes()
		else:
			no()
	else:
		visited = [[False for j in range(m)] for i in range(n)]
		dfs(n - 1, m - 1, visited)
		cond = True
		for (i, j) in Gloc:
			cond = cond and visited[i][j]
		if cond:
			yes()
		else:
			no()


import math as mt
import sys, string
input = sys.stdin.readline
from collections import defaultdict
from heapq import heappush, heapify, heappop
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
t = I()
for _ in range(t):
	(n, m) = M()
	v = defaultdict(int)
	l = []
	c = 0
	f = 1
	for j in range(n):
		s = input().strip()
		s = list(s)
		x = 0
		for i in range(m):
			if s[i] == 'G':
				c += 1
			if s[i] == 'B':
				if i < m - 1:
					if s[i + 1] == '.':
						s[i + 1] = '#'
					if s[i + 1] == 'G':
						f = 0
				if i > 0:
					if s[i - 1] == '.':
						s[i - 1] = '#'
					if s[i - 1] == 'G':
						f = 0
			if len(l) > 0:
				if l[-1][i] == 'B' and s[i] == '.':
					s[i] = '#'
				if l[-1][i] == 'B' and s[i] == 'G':
					f = 0
				if s[i] == 'B' and l[-1][i] == '.':
					l[-1][i] = '#'
				if l[-1][i] == 'G' and s[i] == 'B':
					f = 0
		l.append(s)
	if f == 0:
		print('No')
	elif c == 0:
		print('Yes')
	elif l[n - 1][m - 1] == '#':
		print('No')
	else:
		q = [(n - 1, m - 1)]
		v[q[0][0], q[0][1]] = 1
		while len(q) != 0:
			i = q[0][0]
			j = q[0][1]
			g = []
			if i > 0:
				g.append((i - 1, j))
			if i < n - 1:
				g.append((i + 1, j))
			if j > 0:
				g.append((i, j - 1))
			if j < m - 1:
				g.append((i, j + 1))
			for k in g:
				if v[k] == 0:
					v[k] = 1
					if l[k[0]][k[1]] == 'G':
						c -= 1
						if c == 0:
							f = 0
							break
						q.append((k[0], k[1]))
					elif l[k[0]][k[1]] == '.':
						q.append((k[0], k[1]))
			if f == 0:
				break
			q = q[1:]
		if f:
			print('No')
		else:
			print('Yes')


import sys
Ri = lambda : [int(x) for x in sys.stdin.readline().split()]
ri = lambda : sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def Yes():
	print('Yes')

def No():
	print('No')

def ok(i, j):
	if 0 <= i < n and 0 <= j < m:
		return True
	return False
from types import GeneratorType

def bootstrap(func, stack=[]):

	def wrapped_function(*args, **kwargs):
		if stack:
			return func(*args, **kwargs)
		else:
			call = func(*args, **kwargs)
			while True:
				if type(call) is GeneratorType:
					stack.append(call)
					call = next(call)
				else:
					stack.pop()
					if not stack:
						break
					call = stack[-1].send(call)
			return call
	return wrapped_function

@bootstrap
def dfs(i, j):
	vis[i][j] = True
	if ok(i + 1, j) and (not vis[i + 1][j]) and (not st[i + 1][j] == '#'):
		yield dfs(i + 1, j)
	if ok(i - 1, j) and (not vis[i - 1][j]) and (not st[i - 1][j] == '#'):
		yield dfs(i - 1, j)
	if ok(i, j + 1) and (not vis[i][j + 1]) and (not st[i][j + 1] == '#'):
		yield dfs(i, j + 1)
	if ok(i, j - 1) and (not vis[i][j - 1]) and (not st[i][j - 1] == '#'):
		yield dfs(i, j - 1)
	yield None
for _ in range(int(ri())):
	(n, m) = Ri()
	st = []
	for i in range(n):
		temp = ri()
		temp = [i for i in temp]
		st.append(temp)
	flag = True
	for i in range(n):
		for j in range(m):
			if st[i][j] == 'B' and ok(i + 1, j) and (st[i + 1][j] == 'G'):
				flag = False
				break
			if st[i][j] == 'B' and ok(i, j + 1) and (st[i][j + 1] == 'G'):
				flag = False
				break
			if st[i][j] == 'B' and ok(i - 1, j) and (st[i - 1][j] == 'G'):
				flag = False
				break
			if st[i][j] == 'B' and ok(i, j - 1) and (st[i][j - 1] == 'G'):
				flag = False
				break
		if not flag:
			break
	if not flag:
		No()
	else:
		for i in range(n):
			for j in range(m):
				if st[i][j] == 'B' and ok(i + 1, j) and (st[i + 1][j] == '.'):
					st[i + 1][j] = '#'
				if st[i][j] == 'B' and ok(i, j + 1) and (st[i][j + 1] == '.'):
					st[i][j + 1] = '#'
				if st[i][j] == 'B' and ok(i - 1, j) and (st[i - 1][j] == '.'):
					st[i - 1][j] = '#'
				if st[i][j] == 'B' and ok(i, j - 1) and (st[i][j - 1] == '.'):
					st[i][j - 1] = '#'
		vis = list2d(n, m, False)
		flag = True
		if st[n - 1][m - 1] != '#':
			dfs(n - 1, m - 1)
		for i in range(n):
			for j in range(m):
				if st[i][j] == 'B' and vis[i][j]:
					flag = False
					break
				if st[i][j] == 'G' and (not vis[i][j]):
					flag = False
					break
			if not flag:
				break
		if not flag:
			No()
		else:
			Yes()


def runTest(arr):
	Gs = set()
	Bs = set()
	for i in range(len(arr)):
		for j in range(len(arr[0])):
			if arr[i][j] == 'B':
				for i_ in (i - 1, i, i + 1):
					for j_ in (j - 1, j, j + 1):
						if (i != i_ and j == j_ or (i == i_ and j != j_)) and 0 <= i_ < len(arr) and (0 <= j_ < len(arr[0])) and (arr[i_][j_] == '.'):
							arr[i_][j_] = '#'
				Bs.add((i, j))
			if arr[i][j] == 'G':
				Gs.add((i, j))
	if arr[-1][-1] != '#':
		stack = [(len(arr) - 1, len(arr[0]) - 1)]
	else:
		stack = []
	exploredSet = set()
	while stack:
		(i, j) = stack.pop()
		exploredSet.add((i, j))
		if (i, j) in Bs:
			print('No')
			return
		if (i, j) in Gs:
			Gs.remove((i, j))
		for i_ in (i - 1, i, i + 1):
			for j_ in (j - 1, j, j + 1):
				if (i != i_ and j == j_ or (i == i_ and j != j_)) and 0 <= i_ < len(arr) and (0 <= j_ < len(arr[0])) and ((i_, j_) not in exploredSet) and (arr[i_][j_] != '#'):
					stack.append((i_, j_))
	if len(Gs) == 0:
		print('Yes')
	else:
		print('No')
	return
t = int(input())
for _ in range(t):
	(n, m) = [int(z) for z in input().split()]
	arr = []
	for __ in range(n):
		arr.append(list(input()))
	runTest(arr)


import collections
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	matrix = []
	fail = False
	num_g = 0
	for j in range(n):
		matrix.append(list(input()))
	directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]
	for i in range(n):
		for j in range(m):
			if matrix[i][j] == 'G':
				num_g += 1
			elif matrix[i][j] == 'B':
				for (di, dj) in directions:
					if di + i < 0 or di + i >= n or dj + j < 0 or (dj + j >= m) or (matrix[di + i][dj + j] == 'B'):
						continue
					elif matrix[di + i][dj + j] == 'G':
						fail = True
						break
					matrix[di + i][dj + j] = '#'
	if num_g == 0:
		print('Yes')
		continue
	if matrix[n - 1][m - 1] == '#' or fail == True:
		print('No')
		continue
	else:
		directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]
		q = collections.deque()
		q.append((n - 1, m - 1))
		matrix[n - 1][m - 1] = '#'
		while q:
			(i, j) = q.popleft()
			for (di, dj) in directions:
				if di + i < 0 or di + i >= n or dj + j < 0 or (dj + j >= m) or (matrix[di + i][dj + j] == '#'):
					continue
				if matrix[di + i][dj + j] == 'G':
					num_g -= 1
				if matrix[di + i][dj + j] == 'B':
					fail = True
					break
				matrix[di + i][dj + j] = '#'
				q.append((di + i, dj + j))
		if fail == True:
			print('No')
			continue
		if num_g == 0:
			print('Yes')
			continue
		else:
			print('No')
			continue


from collections import deque
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.append(list(input()))
	g = []
	b = []
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'G':
				g.append((i, j))
			elif a[i][j] == 'B':
				b.append((i, j))
	if len(g) == 0:
		print('Yes')
		continue
	possible = True
	for b_i in b:
		(i, j) = b_i
		if i != 0 and a[i - 1][j] == '.':
			a[i - 1][j] = '#'
		if i != n - 1 and a[i + 1][j] == '.':
			a[i + 1][j] = '#'
		if j != 0 and a[i][j - 1] == '.':
			a[i][j - 1] = '#'
		if j != m - 1 and a[i][j + 1] == '.':
			a[i][j + 1] = '#'
	if a[n - 1][m - 1] == '#':
		print('No')
		continue
	visited = set()
	d = deque()
	d.append((n - 1, m - 1))
	visited.add((n - 1, m - 1))
	while len(d) != 0:
		(i, j) = d[0]
		d.popleft()
		if a[i][j] == 'G':
			g.remove((i, j))
		if a[i][j] == 'B':
			possible = False
			break
		if i != 0 and a[i - 1][j] != '#' and (not (i - 1, j) in visited):
			d.append((i - 1, j))
			visited.add((i - 1, j))
		if i != n - 1 and a[i + 1][j] != '#' and (not (i + 1, j) in visited):
			d.append((i + 1, j))
			visited.add((i + 1, j))
		if j != 0 and a[i][j - 1] != '#' and (not (i, j - 1) in visited):
			d.append((i, j - 1))
			visited.add((i, j - 1))
		if j != m - 1 and a[i][j + 1] != '#' and (not (i, j + 1) in visited):
			d.append((i, j + 1))
			visited.add((i, j + 1))
	if not possible or len(g) != 0:
		print('No')
	else:
		print('Yes')


def check_bad_guy(row_index, col_index, board):
	if row_index > 0:
		if board[row_index - 1][col_index] == 'B':
			return True
	if row_index < len(board) - 1:
		if board[row_index + 1][col_index] == 'B':
			return True
	if col_index > 0:
		if board[row_index][col_index - 1] == 'B':
			return True
	if col_index < len(board[0]) - 1:
		if board[row_index][col_index + 1] == 'B':
			return True
	return False

def check_color(row_index, col_index, board_color):
	neighbouring_colors = list()
	if row_index > 0:
		if board_color[row_index - 1][col_index] != 0:
			neighbouring_colors.append(board_color[row_index - 1][col_index])
	if col_index > 0:
		if board_color[row_index][col_index - 1] != 0:
			neighbouring_colors.append(board_color[row_index][col_index - 1])
	return neighbouring_colors

def solve(board):
	n = len(board)
	m = len(board[0])
	if board[n - 1][m - 1] == 'B':
		return False
	color_connections = dict()
	available_color = 1
	board_color = [[0] * m for i in range(n)]
	good_guys = set()
	for row_index in range(n):
		for col_index in range(m):
			if board[row_index][col_index] == '.':
				if check_bad_guy(row_index, col_index, board):
					board[row_index][col_index] == '#'
				else:
					neighbouring_colors = check_color(row_index, col_index, board_color)
					if len(neighbouring_colors) == 0:
						board_color[row_index][col_index] = available_color
						color_connections[available_color] = set()
						available_color += 1
					elif len(neighbouring_colors) == 1:
						board_color[row_index][col_index] = neighbouring_colors[0]
					elif len(neighbouring_colors) == 2:
						board_color[row_index][col_index] = neighbouring_colors[0]
						color_connections[neighbouring_colors[0]].add(neighbouring_colors[1])
						color_connections[neighbouring_colors[1]].add(neighbouring_colors[0])
			elif board[row_index][col_index] == 'G':
				good_guys.add((row_index, col_index))
				if check_bad_guy(row_index, col_index, board):
					return False
				else:
					neighbouring_colors = check_color(row_index, col_index, board_color)
					if len(neighbouring_colors) == 0:
						board_color[row_index][col_index] = available_color
						color_connections[available_color] = set()
						available_color += 1
					elif len(neighbouring_colors) == 1:
						board_color[row_index][col_index] = neighbouring_colors[0]
					elif len(neighbouring_colors) == 2:
						board_color[row_index][col_index] = neighbouring_colors[0]
						color_connections[neighbouring_colors[0]].add(neighbouring_colors[1])
						color_connections[neighbouring_colors[1]].add(neighbouring_colors[0])
	return evaluate_color(board_color, good_guys, color_connections)

def evaluate_color(board_color, good_guys, color_connections):
	n = len(board_color)
	m = len(board_color[0])
	end_color = board_color[n - 1][m - 1]
	if len(good_guys) == 0:
		return True
	elif end_color == 0:
		return False
	end_connections = set()
	checked = dict()
	stack = [end_color]
	checked[end_color] = True
	while len(stack) != 0:
		current_color = stack.pop()
		end_connections.add(current_color)
		for color in color_connections[current_color]:
			if color not in checked:
				stack.append(color)
				checked[color] = True
	for (row_index, col_index) in good_guys:
		if board_color[row_index][col_index] not in end_connections:
			return False
	return True
t = int(input())
for testcase in range(t):
	(n, m) = list(map(int, input().split()))
	board = [0] * n
	for row_index in range(n):
		board[row_index] = list(input())
	if solve(board):
		print('Yes')
	else:
		print('No')


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(r, c) = map(int, input().split())
	grid = []
	for i in range(r):
		s = input()
		grid.append(list(s))
	(f, cnt) = (0, 0)
	for i in range(r):
		for j in range(c):
			if grid[i][j] == 'B':
				if i + 1 < r:
					cur = grid[i + 1][j]
					if cur == 'G':
						f = 1
						break
					elif cur == '.':
						grid[i + 1][j] = '#'
				if i - 1 >= 0:
					cur = grid[i - 1][j]
					if cur == 'G':
						f = 1
						break
					elif cur == '.':
						grid[i - 1][j] = '#'
				if j + 1 < c:
					cur = grid[i][j + 1]
					if cur == 'G':
						f = 1
						break
					elif cur == '.':
						grid[i][j + 1] = '#'
				if j - 1 >= 0:
					cur = grid[i][j - 1]
					if cur == 'G':
						f = 1
						break
					elif cur == '.':
						grid[i][j - 1] = '#'
			elif grid[i][j] == 'G':
				cnt += 1
		if f == 1:
			break
	if f == 1 or (cnt > 0 and grid[r - 1][c - 1] == '#'):
		print('No')
	else:
		q = [[r - 1, c - 1]]
		seen = set()
		seen.add((r - 1, c - 1))
		gc = 0
		while q:
			cur = q.pop(0)
			(x, y) = (cur[0], cur[1])
			if grid[x][y] == 'G':
				gc += 1
			elif grid[x][y] == '#':
				continue
			if x - 1 >= 0:
				if (x - 1, y) not in seen:
					seen.add((x - 1, y))
					q.append([x - 1, y])
			if y - 1 >= 0:
				if (x, y - 1) not in seen:
					seen.add((x, y - 1))
					q.append([x, y - 1])
			if x + 1 < r:
				if (x + 1, y) not in seen:
					seen.add((x + 1, y))
					q.append([x + 1, y])
			if y + 1 < c:
				if (x, y + 1) not in seen:
					seen.add((x, y + 1))
					q.append([x, y + 1])
		if cnt == gc:
			print('Yes')
		else:
			print('No')


import itertools as it
import sys
sys.setrecursionlimit(10 ** 5)
l = [[0, 1], [1, 0], [-1, 0], [0, -1]]
c = 0

def dfs(i, j, d, visited, m, n):
	global c, l
	if d[i][j] == 'G':
		c += 1
	if d[i][j] != '#':
		for k in l:
			if n > i + k[0] > -1 and m > j + k[1] > -1 and ((i + k[0], j + k[1]) not in visited) and (d[i + k[0]][j + k[1]] != '#'):
				visited.add((i + k[0], j + k[1]))
				dfs(i + k[0], j + k[1], d, visited, m, n)

def main():
	global c
	for _ in range(int(input())):
		try:
			c = 0
			(n, m) = map(int, input().split())
			l = [list(input()) for i in range(n)]
			alpha = list(it.chain.from_iterable(l))
			(b, f, g) = ([], 0, 0)
			m1 = -1
			for i in range(n):
				for j in range(m):
					if l[i][j] == 'G':
						m1 = (i, j)
						break
			for i in range(n):
				for j in range(m):
					if l[i][j] == 'B':
						b.append((i, j))
						if i - 1 >= 0 and l[i - 1][j] == 'G':
							f = 1
						if i + 1 <= n - 1 and l[i + 1][j] == 'G':
							f = 1
						if j - 1 >= 0 and l[i][j - 1] == 'G':
							f = 1
						if j + 1 <= m - 1 and l[i][j + 1] == 'G':
							f = 1
						if i - 1 >= 0 and l[i - 1][j] == '.':
							l[i - 1][j] = '#'
						if i + 1 <= n - 1 and l[i + 1][j] == '.':
							l[i + 1][j] = '#'
						if j - 1 >= 0 and l[i][j - 1] == '.':
							l[i][j - 1] = '#'
						if j + 1 <= m - 1 and l[i][j + 1] == '.':
							l[i][j + 1] = '#'
			if m1 != -1:
				dfs(n - 1, m - 1, l, set(), m, n)
				if l[-1][-1] == '#':
					f = 1
			else:
				f = 0
			if f != 1 and alpha.count('G') == c:
				print('Yes')
				pass
			else:
				print('no')
		except Exception as e:
			print(e)
main()


from collections import deque

def solve():
	(n, m) = map(int, input().split())
	s = []
	for _ in range(n):
		s.append(list(input()))
	dxdy = [(-1, 0), (0, -1), (0, 1), (1, 0)]
	for y in range(n):
		for x in range(m):
			if s[y][x] == 'B':
				for (dx, dy) in dxdy:
					if not (0 <= x + dx < m and 0 <= y + dy < n):
						continue
					if s[y + dy][x + dx] == 'G':
						print('No')
						return
					if s[y + dy][x + dx] == '.':
						s[y + dy][x + dx] = '#'
				s[y][x] = '#'
	if s[n - 1][m - 1] == '#':
		q = []
	else:
		q = deque([(m - 1, n - 1)])
	while q:
		(x, y) = q.popleft()
		for (dx, dy) in dxdy:
			if not (0 <= x + dx < m and 0 <= y + dy < n):
				continue
			if s[y + dy][x + dx] in ['#', 'seen']:
				continue
			s[y + dy][x + dx] = 'seen'
			q.append((x + dx, y + dy))
	for i in s:
		if i.count('G'):
			print('No')
			return
	print('Yes')
t = int(input())
for _ in range(t):
	solve()


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import collections

def block(s, b):
	global m
	global n
	global maze
	broke = False
	if b > 0:
		if maze[s][b - 1] == '.':
			maze[s][b - 1] = '#'
		elif maze[s][b - 1] == 'G':
			broke = True
	if b < m - 1:
		if maze[s][b + 1] == '.':
			maze[s][b + 1] = '#'
		elif maze[s][b + 1] == 'G':
			broke = True
	if s > 0:
		if maze[s - 1][b] == '.':
			maze[s - 1][b] = '#'
		elif maze[s - 1][b] == 'G':
			broke = True
	if s < n - 1:
		if maze[s + 1][b] == '.':
			maze[s + 1][b] = '#'
		elif maze[s + 1][b] == 'G':
			broke = True
	return broke
testcases = int(input())
for j in range(testcases):
	(n, m) = map(int, input().split())
	maze = []
	for s in range(n):
		row = [k for k in input()]
		maze.append(row)
	b1 = False
	dict1 = {}
	for s in range(n):
		for b in range(m):
			dict1[s, b] = []
	for s in range(n):
		for b in range(m):
			if maze[s][b] == 'B':
				broke = block(s, b)
				if broke == True:
					b1 = True
					break
	setty = set(['G', '.'])
	good = 0
	for s in range(n):
		for b in range(m):
			if maze[s][b] in setty:
				if maze[s][b] == 'G':
					good += 1
				if b > 0:
					if maze[s][b - 1] in setty:
						dict1[s, b].append((s, b - 1))
				if b < m - 1:
					if maze[s][b + 1] in setty:
						dict1[s, b].append((s, b + 1))
				if s > 0:
					if maze[s - 1][b] in setty:
						dict1[s, b].append((s - 1, b))
				if s < n - 1:
					if maze[s + 1][b] in setty:
						dict1[s, b].append((s + 1, b))
	visited = set([])
	for s in dict1.keys():
		if not s in visited and maze[s[0]][s[1]] == 'G':
			queue = collections.deque([])
			vis = set([s])
			for b in dict1[s]:
				queue.append(b)
				vis.add(b)
				visited.add(b)
			while len(queue) > 0:
				v0 = queue.popleft()
				for b in dict1[v0]:
					if not b in vis:
						vis.add(b)
						queue.append(b)
						if b in visited:
							vis.add((n - 1, m - 1))
							break
						visited.add(b)
				if v0 == (n - 1, m - 1):
					break
			if (n - 1, m - 1) in vis:
				continue
			else:
				b1 = True
				break
	if good >= 1 and maze[n - 1][m - 1] == '#':
		b1 = True
	if b1 == True:
		print('No')
	else:
		print('Yes')


from collections import deque

def solve(maze, n, m):

	def _valid(i, j):
		return i >= 1 and i <= n and (j >= 1) and (j <= m)
	directions = ((1, 0), (0, 1), (-1, 0), (0, -1))
	for row in range(1, n + 1):
		for col in range(1, m + 1):
			if maze[row][col] == 'B':
				for d in directions:
					ni = row + d[0]
					nj = col + d[1]
					if _valid(ni, nj) and maze[ni][nj] == '.':
						maze[ni][nj] = '#'
	queue = deque()
	visited = set()
	if maze[n][m] == '.':
		cell = (n, m)
		queue.appendleft(cell)
		visited.add(cell)
	while queue:
		cell = queue.pop()
		for d in directions:
			ni = cell[0] + d[0]
			nj = cell[1] + d[1]
			if _valid(ni, nj) and maze[ni][nj] != '#':
				neighbour = (ni, nj)
				if neighbour not in visited:
					queue.appendleft(neighbour)
					visited.add(neighbour)
	for row in range(1, n + 1):
		for col in range(1, m + 1):
			if maze[row][col] == 'G' and (row, col) not in visited:
				return False
			if maze[row][col] == 'B' and (row, col) in visited:
				return False
	return True

def solve_for_input():
	(n, m) = map(int, input().split())
	maze = [['#' for _ in range(m + 2)] for _ in range(n + 2)]
	for i in range(1, n + 1):
		maze[i][1:m] = list(input())
	return solve(maze, n, m)
tc = int(input())
while tc > 0:
	print('Yes' if solve_for_input() else 'No')
	tc -= 1


import sys
input = sys.stdin.readline
for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = [['.'] * (m + 1) for _ in range(n + 1)]
	ans = True
	g = list()
	for i in range(n):
		line = input().strip()
		for (j, c) in enumerate(line):
			if c == 'B':
				a[i][j] = 'B'
				if a[i - 1][j] == 'G':
					ans = False
				a[i - 1][j] = '#'
				if a[i + 1][j] == 'G':
					ans = False
				a[i + 1][j] = '#'
				if a[i][j + 1] == 'G':
					ans = False
				a[i][j + 1] = '#'
				if a[i][j - 1] == 'G':
					ans = False
				a[i][j - 1] = '#'
			if c == 'G':
				if a[i][j] == '#':
					ans = False
				a[i][j] = 'G'
				g.append((i, j))
			if c == '#':
				a[i][j] = '#'
	if ans is False:
		print('No')
		continue
	a.pop()
	for l in a:
		l.pop()
	front = [(n - 1, m - 1)]
	visited = {(n - 1, m - 1)}
	while front:
		new_front = []
		for p in front:
			i = a[p[0]][p[1]]
			if i == '.' or i == 'G':
				if i == 'G':
					g.remove(p)
				for (x, y) in ((0, 1), (0, -1), (-1, 0), (1, 0)):
					if p[0] + x == n:
						continue
					if p[1] + y == m:
						continue
					if p[0] + x == -1:
						continue
					if p[1] + y == -1:
						continue
					ni = (p[0] + x, p[1] + y)
					if ni not in visited:
						new_front.append(ni)
						visited.add(ni)
		front = new_front[:]
	if g:
		print('No')
	else:
		print('Yes')


for _ in range(int(input())):

	def solve():
		(n, m) = map(int, input().split())
		a = []
		mat = [[0 for i in range(m)] for j in range(n)]
		good = 0
		for i in range(n):
			a.append(input())
			if 1:
				good += a[-1].count('G')
		if good == 0:
			return 'Yes'
		if m - 2 >= 0 and a[n - 1][m - 2] == 'B':
			return 'No'
		if n - 2 >= 0 and a[n - 2][m - 1] == 'B':
			return 'No'
		if 1:
			for i in range(n):
				for j in range(m):
					st = []
					if a[i][j] in '#':
						mat[i][j] = 1
					if mat[i][j] == 0:
						if a[i][j] == 'B':
							st.append((i, j))
						while st:
							(x, y) = st.pop(0)
							if x + 1 < n and a[x + 1][y] == 'G':
								return 'No'
							if x + 1 < n and a[x + 1][y] in '.':
								mat[x + 1][y] = 1
							if x + 1 < n and a[x + 1][y] == 'B' and (mat[x + 1][y] == 0):
								st.append((x + 1, y))
								mat[i][j] = 1
							if x - 1 >= 0 and a[x - 1][y] == 'G':
								return 'No'
							if x - 1 >= 0 and a[x - 1][y] in '.':
								mat[x - 1][y] = 1
							if x - 1 >= 0 and a[x - 1][y] == 'B' and (mat[x - 1][y] == 0):
								st.append((x - 1, y))
								mat[x - 1][y] = 1
							if y + 1 < m and a[x][y + 1] == 'G':
								return 'No'
							if y + 1 < m and a[x][y + 1] in '.':
								mat[x][y + 1] = 1
							if y + 1 < m and a[x][y + 1] == 'B' and (mat[x][y + 1] == 0):
								st.append((x, y + 1))
								mat[x][y + 1] = 1
							if y - 1 >= 0 and a[x][y - 1] == 'G':
								return 'No'
							if y - 1 >= 0 and a[x][y - 1] in '.':
								mat[x][y - 1] = 1
							if y - 1 >= 0 and a[x][y - 1] == 'B' and (mat[x][y - 1] == 0):
								st.append((x, y - 1))
								mat[x][y - 1] = 1
		st = [(n - 1, m - 1)]
		mat[n - 1][m - 1] = 1
		while st:
			(x, y) = st.pop(0)
			if a[x][y] == 'G':
				good -= 1
			if x + 1 < n and mat[x + 1][y] == 0:
				st.append((x + 1, y))
				mat[x + 1][y] = 1
			if x - 1 >= 0 and mat[x - 1][y] == 0:
				st.append((x - 1, y))
				mat[x - 1][y] = 1
			if y + 1 < m and mat[x][y + 1] == 0:
				st.append((x, y + 1))
				mat[x][y + 1] = 1
			if y - 1 >= 0 and mat[x][y - 1] == 0:
				st.append((x, y - 1))
				mat[x][y - 1] = 1
		if good == 0:
			return 'Yes'
		else:
			return 'No'
	print(solve())


import sys
input = sys.stdin.readline

def inInt():
	return int(input())

def inStr():
	return input().strip('\n')

def inIList():
	return list(map(int, input().split()))

def inSList():
	return input().split()

def bsearch(nums, target):
	N = len(nums or [])
	l = 0
	r = N - 1
	while l <= r:
		mid = (l + r) // 2
		if nums[mid] < target:
			l = mid + 1
		elif nums[mid] > target:
			r = mid - 1
		else:
			return (None, mid, None)
	return (r if r >= 0 else None, None, l if l <= N - 1 else None)

def yesOrNo(val):
	print('YES' if val else 'NO')

def printSpacedArray(nums):
	print(*nums)

def solve():
	grid = []
	(n, m) = inIList()
	for i in range(n):
		grid.append(list(inStr()))
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 'B':
				if i > 0:
					if grid[i - 1][j] == '.':
						grid[i - 1][j] = '#'
				if i < n - 1:
					if grid[i + 1][j] == '.':
						grid[i + 1][j] = '#'
				if j > 0:
					if grid[i][j - 1] == '.':
						grid[i][j - 1] = '#'
				if j < m - 1:
					if grid[i][j + 1] == '.':
						grid[i][j + 1] = '#'
	queue = []
	seen = [[False for j in range(m)] for i in range(n)]
	queue.append((n - 1, m - 1))
	while queue:
		cur = queue[0]
		queue = queue[1:]
		if not seen[cur[0]][cur[1]] and grid[cur[0]][cur[1]] != '#':
			(i, j) = cur
			seen[i][j] = True
			if i > 0:
				queue.append((i - 1, j))
			if i < n - 1:
				queue.append((i + 1, j))
			if j > 0:
				queue.append((i, j - 1))
			if j < m - 1:
				queue.append((i, j + 1))
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 'B':
				if seen[i][j]:
					return 'No'
			elif grid[i][j] == 'G':
				if not seen[i][j]:
					return 'No'
	return 'Yes'
tests = inInt()
for case in range(tests):
	print(solve())


def answer(n, m, A):
	if A[n - 1][m - 1] == 'B':
		return 'No'
	count = 0
	for i in range(n):
		for j in range(m):
			if A[i][j] == 'B':
				if j - 1 >= 0 and A[i][j - 1] == 'G' or (j + 1 < m and A[i][j + 1] == 'G') or (i - 1 >= 0 and A[i - 1][j] == 'G') or (i + 1 < n and A[i + 1][j] == 'G'):
					return 'No'
				else:
					if j - 1 >= 0 and A[i][j - 1] == '.':
						A[i][j - 1] = '#'
					if j + 1 < m and A[i][j + 1] == '.':
						A[i][j + 1] = '#'
					if i - 1 >= 0 and A[i - 1][j] == '.':
						A[i - 1][j] = '#'
					if i + 1 < n and A[i + 1][j] == '.':
						A[i + 1][j] = '#'
			if A[i][j] == 'G':
				count += 1
	if A[n - 1][m - 1] == '#' and count != 0:
		return 'No'
	if count == 0:
		return 'Yes'
	dp = [[0 for i in range(m)] for j in range(n)]
	s = [[n - 1, m - 1]]
	while len(s) > 0:
		l = s.pop()
		r = l[0]
		c = l[1]
		if c + 1 < m and A[r][c + 1] != '#' and (dp[r][c + 1] == 0):
			s.append([r, c + 1])
		if c - 1 >= 0 and A[r][c - 1] != '#' and (dp[r][c - 1] == 0):
			s.append([r, c - 1])
		if r - 1 >= 0 and A[r - 1][c] != '#' and (dp[r - 1][c] == 0):
			s.append([r - 1, c])
		if r + 1 < n and A[r + 1][c] != '#' and (dp[r + 1][c] == 0):
			s.append([r + 1, c])
		dp[r][c] = 1
	for i in range(n):
		for j in range(m):
			if A[i][j] == 'G' and dp[i][j] != 1:
				return 'No'
	return 'Yes'
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(list(input()))
	print(answer(n, m, l))


from collections import deque
q = int(input())
for _ in range(q):
	(n, m) = list(map(int, input().split(' ')))
	A = []
	for i in range(n):
		A.append(list(input()))
	see = False
	for i in range(n):
		for j in range(m):
			if A[i][j] == 'G':
				see = True
	if see == False:
		print('Yes')
		continue

	def CHECK(i, j):
		if i > 0:
			if A[i - 1][j] == 'G':
				return -1
			elif A[i - 1][j] != 'B':
				A[i - 1][j] = '#'
		if i < n - 1:
			if A[i + 1][j] == 'G':
				return -1
			elif A[i + 1][j] != 'B':
				A[i + 1][j] = '#'
		if j > 0:
			if A[i][j - 1] == 'G':
				return -1
			elif A[i][j - 1] != 'B':
				A[i][j - 1] = '#'
		if j < m - 1:
			if A[i][j + 1] == 'G':
				return -1
			elif A[i][j + 1] != 'B':
				A[i][j + 1] = '#'
	done = False
	for i in range(n):
		if done == True:
			break
		for j in range(m):
			if A[i][j] == 'B':
				c = CHECK(i, j)
				if c == -1:
					done = True
					break
	if done == True:
		print('No')
		continue
	if A[n - 1][m - 1] in '#B':
		print('No')
		continue
	G = {}
	col = {}
	for i in range(n):
		for j in range(m):
			if A[i][j] not in '#B':
				key = (i, j)
				G[key] = []
				col[key] = 'w'
				if i > 0:
					if A[i - 1][j] not in '#B':
						G[key].append((i - 1, j))
				if i < n - 1:
					if A[i + 1][j] not in '#B':
						G[key].append((i + 1, j))
				if j > 0:
					if A[i][j - 1] not in '#B':
						G[key].append((i, j - 1))
				if j < m - 1:
					if A[i][j + 1] not in '#B':
						G[key].append((i, j + 1))
	Q = deque([])
	Q.append((n - 1, m - 1))
	while len(Q) != 0:
		u = Q.popleft()
		l = G[u]
		for v in l:
			if col[v] == 'w':
				col[v] = 'b'
				Q.append(v)
		col[u] = 'b'
	for i in range(n):
		if done:
			break
		for j in range(m):
			if A[i][j] == 'G':
				if col[i, j] != 'b':
					done = True
					break
	if done:
		print('No')
	else:
		print('Yes')


import os
import sys
from io import BytesIO, IOBase

def main():
	di = (-1, 1, 0, 0)
	dj = (0, 0, -1, 1)

	def dfs(maze, i, j, visited, n, m):
		if maze[i][j] != '#':
			visited[i][j] = True
		else:
			return
		for d in range(4):
			ni = i + di[d]
			nj = j + dj[d]
			if ni >= 0 and nj >= 0 and (ni < n) and (nj < m) and (not visited[ni][nj]):
				dfs(maze, ni, nj, visited, n, m)
		return
	cases = int(input())
	for t in range(cases):
		(n, m) = r_array()
		maze = [list(input()) for i in range(n)]
		gcount = 0
		f = 0
		for i in range(n):
			for j in range(m):
				if maze[i][j] == 'B':
					if j < m - 1:
						if maze[i][j + 1] == 'G':
							f = 1
							break
						elif maze[i][j + 1] == '.':
							maze[i][j + 1] = '#'
					if j > 0:
						if maze[i][j - 1] == 'G':
							f = 1
							break
						elif maze[i][j - 1] == '.':
							maze[i][j - 1] = '#'
					if i < n - 1:
						if maze[i + 1][j] == 'G':
							f = 1
							break
						elif maze[i + 1][j] == '.':
							maze[i + 1][j] = '#'
					if i > 0:
						if maze[i - 1][j] == 'G':
							f = 1
							break
						elif maze[i - 1][j] == '.':
							maze[i - 1][j] = '#'
				elif maze[i][j] == 'G':
					gcount += 1
			if f == 1:
				break
		if maze[-1][-1] == '#':
			if gcount == 0:
				write('Yes')
			else:
				write('No')
			continue
		if f == 1:
			write('No')
			continue
		visited = [[False for j in range(m)] for i in range(n)]
		dfs(maze, n - 1, m - 1, visited, n, m)
		f = 0
		for i in range(n):
			for j in range(m):
				if maze[i][j] == 'G' and (not visited[i][j]):
					f = 1
					break
			if f == 1:
				break
		if f == 1:
			write('No')
		else:
			write('Yes')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def input():
	return sys.stdin.readline().rstrip('\r\n')

def write(*args, end='\n'):
	for x in args:
		sys.stdout.write(str(x) + ' ')
	sys.stdout.write(end)

def r_array():
	return [int(x) for x in input().split()]

def r_int():
	return int(input())

def w_array(arr):
	for x in arr:
		write(x, end=' ')
	write()
main()


import sys
input = sys.stdin.readline
di = (-1, 1, 0, 0)
dj = (0, 0, -1, 1)

def dfs(maze, i, j, visited, n, m):
	if maze[i][j] != '#':
		visited[i][j] = True
	else:
		return
	for d in range(4):
		ni = i + di[d]
		nj = j + dj[d]
		if ni >= 0 and nj >= 0 and (ni < n) and (nj < m) and (not visited[ni][nj]):
			dfs(maze, ni, nj, visited, n, m)
	return
cases = int(input())
for t in range(cases):
	(n, m) = list(map(int, input().split()))
	maze = [list(input()) for i in range(n)]
	gcount = 0
	f = 0
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'B':
				if j < m - 1:
					if maze[i][j + 1] == 'G':
						f = 1
						break
					elif maze[i][j + 1] == '.':
						maze[i][j + 1] = '#'
				if j > 0:
					if maze[i][j - 1] == 'G':
						f = 1
						break
					elif maze[i][j - 1] == '.':
						maze[i][j - 1] = '#'
				if i < n - 1:
					if maze[i + 1][j] == 'G':
						f = 1
						break
					elif maze[i + 1][j] == '.':
						maze[i + 1][j] = '#'
				if i > 0:
					if maze[i - 1][j] == 'G':
						f = 1
						break
					elif maze[i - 1][j] == '.':
						maze[i - 1][j] = '#'
			elif maze[i][j] == 'G':
				gcount += 1
		if f == 1:
			break
	if maze[-1][-1] == '#':
		if gcount == 0:
			print('Yes')
		else:
			print('No')
		continue
	if f == 1:
		print('No')
		continue
	visited = [[False for j in range(m)] for i in range(n)]
	dfs(maze, n - 1, m - 1, visited, n, m)
	f = 0
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'G' and (not visited[i][j]):
				f = 1
				break
		if f == 1:
			break
	if f == 1:
		print('No')
	else:
		print('Yes')


from sys import stdin, stdout
import heapq as hq
from collections import defaultdict
t = int(input())
for tc in range(t):
	(n, m) = list(map(int, stdin.readline().split()))
	mat = []
	boundery = ['#' for _ in range(m + 2)]
	mat.append(boundery)
	for nc in range(n):
		instr = list(stdin.readline().strip())
		mat.append(['#'] + instr + ['#'])
	mat.append(boundery)
	n += 2
	m += 2
	valid = True
	(bcount, gcount) = (0, 0)
	for row in mat:
		for char in row:
			if char == 'B':
				bcount += 1
			elif char == 'G':
				gcount += 1
	if gcount == 0:
		pass
	else:
		if bcount > 0:
			for i in range(n):
				for j in range(m):
					if mat[i][j] == 'B':
						if mat[i - 1][j] == 'G':
							valid = False
						elif mat[i - 1][j] == 'B':
							pass
						else:
							mat[i - 1][j] = '#'
						if mat[i + 1][j] == 'G':
							valid = False
						elif mat[i + 1][j] == 'B':
							pass
						else:
							mat[i + 1][j] = '#'
						if mat[i][j - 1] == 'G':
							valid = False
						elif mat[i][j - 1] == 'B':
							pass
						else:
							mat[i][j - 1] = '#'
						if mat[i][j + 1] == 'G':
							valid = False
						elif mat[i][j + 1] == 'B':
							pass
						else:
							mat[i][j + 1] = '#'
		found = {(n - 2, m - 2)}
		curgen = [(n - 2, m - 2)]
		nextgen = []
		if mat[n - 2][m - 2] == '#':
			curgen = []
			valid = False
		while len(curgen) + len(nextgen) > 0:
			if len(curgen) == 0:
				curgen = nextgen
				nextgen = []
			(i, j) = curgen[0]
			if mat[i][j] == 'G':
				mat[i][j] = '.'
			if mat[i][j] == 'B':
				valid = False
			if mat[i - 1][j] in ('.', 'G') and (i - 1, j) not in found:
				found.add((i - 1, j))
				nextgen.append((i - 1, j))
			if mat[i + 1][j] in ('.', 'G') and (i + 1, j) not in found:
				found.add((i + 1, j))
				nextgen.append((i + 1, j))
			if mat[i][j - 1] in ('.', 'G') and (i, j - 1) not in found:
				found.add((i, j - 1))
				nextgen.append((i, j - 1))
			if mat[i][j + 1] in ('.', 'G') and (i, j + 1) not in found:
				found.add((i, j + 1))
				nextgen.append((i, j + 1))
			curgen = curgen[1:]
		for i in range(n):
			for j in range(m):
				if mat[i][j] == 'G':
					valid = False
	if valid:
		res = 'Yes'
	else:
		res = 'No'
	stdout.write(str(res) + '\n')


from collections import defaultdict as dd, deque as dq
import sys
input = sys.stdin.readline
t = int(input())

def bfs(ll, i, n, m):
	(x, y) = i
	for (X, Y) in [(x + 1, y), (x, y + 1), (x - 1, y), (x, y - 1)]:
		if X < n and Y < m and (X >= 0) and (Y >= 0):
			if ll[X][Y] == '.':
				ll[X][Y] = '#'

def gbfs(ll, i, vis, n, m):
	q = dq([i])
	vis[i] = 1
	lol = 0
	while q:
		a = q.pop()
		(x, y) = a
		if (x, y) == (n - 1, m - 1):
			lol = 1
		for (X, Y) in [(x + 1, y), (x, y + 1), (x - 1, y), (x, y - 1)]:
			if X < n and Y < m and (X >= 0) and (Y >= 0):
				if vis[X, Y] == 0:
					if ll[X][Y] == '.' or ll[X][Y] == 'G':
						q.appendleft((X, Y))
					elif ll[X][Y] == 'B':
						return False
					elif ll[X][Y] == 'TG':
						return True
					vis[X, Y] = 1
	if lol:
		return True
	return False
while t:
	(n, m) = map(int, input().split())
	bb = []
	gb = []
	ll = []
	lol = 0
	for i in range(n):
		s = list(input().split()[0].strip())
		ll.append(s)
		for j in range(m):
			if ll[i][j] == 'B':
				bb.append((i, j))
			if ll[i][j] == 'G':
				gb.append((i, j))
	for i in bb:
		bfs(ll, i, n, m)
	for i in gb:
		vis = dd(int)
		if not gbfs(ll, i, vis, n, m):
			lol = 1
			break
		else:
			ll[i[0]][i[1]] = 'TG'
	if lol:
		print('No')
	else:
		print('Yes')
	t -= 1


import sys
input = lambda : sys.stdin.readline().rstrip('\n')
D = [(-1, 0), (1, 0), (0, -1), (0, 1)]

def case():
	(n, m) = map(int, input().split())
	M = [list(input()) for _ in range(n)]
	good = set()
	for y in range(n):
		for x in range(m):
			c = M[y][x]
			if c == 'G':
				good.add((x, y))
			elif c == 'B':
				for (dx, dy) in D:
					nx = x + dx
					ny = y + dy
					if nx < 0 or ny < 0 or nx >= m or (ny >= n):
						continue
					if M[ny][nx] == 'G':
						print('No')
						return
					elif M[ny][nx] != 'B':
						M[ny][nx] = '#'
	if M[-1][-1] == '#':
		print('No' if good else 'Yes')
		return
	V = [[False] * m for _ in range(n)]
	V[n - 1][m - 1] = True
	Q = [(m - 1, n - 1)]
	while Q:
		(x, y) = Q.pop()
		good.discard((x, y))
		for (dx, dy) in D:
			nx = x + dx
			ny = y + dy
			if nx < 0 or ny < 0 or nx >= m or (ny >= n):
				continue
			if M[ny][nx] == '#' or V[ny][nx]:
				continue
			V[ny][nx] = True
			Q.append((nx, ny))
	print('Yes' if not good else 'No')
for _ in range(int(input())):
	case()


import sys
input = sys.stdin.readline
import math

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input().strip()
	return list(s[:len(s)])

def invr():
	return map(int, input().strip().split())

def from_file(f):
	return f.readline

def dfs(n, m, A, token, visited):
	if A[n - 1][m - 1] == '#':
		return 0

	def can_move(ni, nj):
		return 0 <= ni < n and 0 <= nj < m and (A[ni][nj] not in ('#', 'B'))
	count = 0
	stack = [(n - 1, m - 1)]
	visited[n - 1][m - 1] = token
	while stack:
		cur = stack.pop()
		(i, j) = cur
		if A[i][j] == 'G':
			count += 1
		for (ni, nj) in ((i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)):
			if can_move(ni, nj) and visited[ni][nj] != token:
				visited[ni][nj] = token
				stack.append((ni, nj))
	return count

def check_neibs(n, m, i, j, A):
	for (p, q) in ((i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)):
		if 0 <= p < n and 0 <= q < m and (A[p][q] != 'B'):
			A[p][q] = '#'

def solution(n, m, A, visited, token):
	(cG, cB) = (0, 0)
	for (i, row) in enumerate(A):
		for (j, s) in enumerate(row):
			if s == 'G':
				cG += 1
	for (i, row) in enumerate(A):
		for (j, s) in enumerate(row):
			if s == 'B':
				cB += 1
				check_neibs(n, m, i, j, A)
	if cG == 0:
		return 'Yes'
	rG = dfs(n, m, A, token, visited)
	if cG != rG:
		return 'No'
	return 'yes'
t = inp()
visited = [[-1] * 60 for _ in range(60)]
for token in range(t):
	(n, m) = invr()
	A = []
	for _ in range(n):
		A.append(list(input().strip()))
	print(solution(n, m, A, visited, token + 1))


from collections import deque
inp = lambda : map(int, input().split())
(ts,) = inp()
char_map = {'#': -1, '.': 0, 'G': 1, 'B': 2}
for _ in range(ts):
	(m, n) = inp()
	g_pos = set()
	arr = [[0] * n for i in range(m)]
	for i in range(m):
		row = input()
		for j in range(n):
			arr[i][j] = char_map[row[j]]
			if row[j] == 'G':
				g_pos.add((i, j))
	if len(g_pos) == 0:
		print('yes')
		continue
	for i in range(m):
		for j in range(n):
			if arr[i][j] == 2:
				if i < m - 1 and arr[i + 1][j] != 2:
					arr[i + 1][j] = -1
				if i > 0 and arr[i - 1][j] != 2:
					arr[i - 1][j] = -1
				if j < n - 1 and arr[i][j + 1] != 2:
					arr[i][j + 1] = -1
				if j > 0 and arr[i][j - 1] != 2:
					arr[i][j - 1] = -1
	if arr[m - 1][n - 1] == -1:
		print('no')
		continue
	q = deque()
	q.append((m - 1, n - 1))
	seen = set()
	while q:
		(i, j) = q.popleft()
		if (i, j) not in seen:
			seen.add((i, j))
		else:
			continue
		if i > 0 and arr[i - 1][j] != -1 and ((i - 1, j) not in seen):
			q.append((i - 1, j))
		if j > 0 and arr[i][j - 1] != -1 and ((i, j - 1) not in seen):
			q.append((i, j - 1))
		if i < m - 1 and arr[i + 1][j] != -1 and ((i + 1, j) not in seen):
			q.append((i + 1, j))
		if j < n - 1 and arr[i][j + 1] != -1 and ((i, j + 1) not in seen):
			q.append((i, j + 1))
	if seen.intersection(g_pos) == g_pos:
		print('yes')
	else:
		print('no')


def test(n, m, a):
	Good = 0
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'G':
				Good += 1
			if a[i][j] == 'B':
				if i + 1 < n:
					if a[i + 1][j] == 'G':
						return 'No'
					elif a[i + 1][j] != 'B':
						a[i + 1][j] = '#'
				if i - 1 >= 0:
					if a[i - 1][j] == 'G':
						return 'No'
					elif a[i - 1][j] != 'B':
						a[i - 1][j] = '#'
				if j + 1 < m:
					if a[i][j + 1] == 'G':
						return 'No'
					elif a[i][j + 1] != 'B':
						a[i][j + 1] = '#'
				if j - 1 >= 0:
					if a[i][j - 1] == 'G':
						return 'No'
					elif a[i][j - 1] != 'B':
						a[i][j - 1] = '#'
	if Good == 0:
		return 'Yes'
	if a[n - 1][m - 1] == '#':
		return 'No'
	sosed = set()
	sosed.add((n - 1, m - 1))
	posetil = set()
	posetil.add((n - 1, m - 1))
	while len(sosed) > 0:
		sosed2 = set()
		for i in sosed:
			if a[i[0]][i[1]] == 'G':
				Good -= 1
			if i[0] + 1 < n and a[i[0] + 1][i[1]] != '#' and ((i[0] + 1, i[1]) not in posetil):
				sosed2.add((i[0] + 1, i[1]))
			if i[0] - 1 >= 0 and a[i[0] - 1][i[1]] != '#' and ((i[0] - 1, i[1]) not in posetil):
				sosed2.add((i[0] - 1, i[1]))
			if i[1] + 1 < m and a[i[0]][i[1] + 1] != '#' and ((i[0], i[1] + 1) not in posetil):
				sosed2.add((i[0], i[1] + 1))
			if i[1] - 1 >= 0 and a[i[0]][i[1] - 1] != '#' and ((i[0], i[1] - 1) not in posetil):
				sosed2.add((i[0], i[1] - 1))
		sosed = sosed2.copy()
		posetil |= sosed2
	if Good == 0:
		return 'Yes'
	else:
		return 'No'
ans = []
for kek in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.append(list(input()))
	ans.append(test(n, m, a))
print(*ans, sep='\n')


from sys import stdin
input = stdin.readline
import bisect
import math
for xoxo in range(1):
	for _ in range(int(input())):

		def func(n, m, i, j):
			p = []
			if i + 1 < n:
				p.append([i + 1, j])
			if j + 1 < m:
				p.append([i, j + 1])
			if i != 0:
				p.append([i - 1, j])
			if j != 0:
				p.append([i, j - 1])
			return p

		def bfs(g):
			vis = [[0 for i in range(m)] for j in range(n)]
			vis[-1][-1] = 1
			q = [[n - 1, m - 1]]
			it = -1
			while it < len(q) - 1:
				it += 1
				x = func(n, m, q[it][0], q[it][1])
				for i in range(len(x)):
					if g[x[i][0]][x[i][1]] == 0 and vis[x[i][0]][x[i][1]] == 0:
						q.append([x[i][0], x[i][1]])
						vis[x[i][0]][x[i][1]] = 1
			t = 0
			for i in range(len(q)):
				if a[q[i][0]][q[i][1]] == 'G':
					t += 1
			return t
		a = []
		(n, m) = map(int, input().split())
		grid = [[0 for i in range(m)] for j in range(n)]
		c = 0
		for i in range(n):
			s = input()[:m]
			for j in range(m):
				if s[j] == '#':
					grid[i][j] = -1
				if s[j] == 'G':
					c += 1
			a.append(s)
		if c == 0 and a[n - 1][m - 1] != 'B':
			print('Yes')
		elif a[n - 1][m - 1] == '#' and c != 0:
			print('No')
		elif a[n - 1][m - 1] == 'B':
			print('No')
		else:
			ans = 'Yes'
			for i in range(n):
				if ans == 'No':
					break
				for j in range(m):
					if ans == 'No':
						break
					if a[i][j] == 'B':
						x = func(n, m, i, j)
						for k in range(len(x)):
							if a[x[k][0]][x[k][1]] == '.':
								grid[x[k][0]][x[k][1]] = -1
							if a[x[k][0]][x[k][1]] == 'G':
								ans = 'No'
								break
			if ans == 'No':
				print(ans)
				continue
			if grid[-1][-1] != -1:
				cc = bfs(grid)
				if cc == c:
					print('Yes')
				else:
					print('No')
			else:
				print('No')


from sys import stdin, exit, setrecursionlimit
from collections import deque
input = stdin.readline
lmi = lambda : list(map(int, input().split()))
mi = lambda : map(int, input().split())
si = lambda : input().strip('\n')
ssi = lambda : input().strip('\n').split()

def bfs(y, x):
	q = deque([(y, x)])
	while q:
		(y, x) = q.popleft()
		if grid[y][x] == 'G':
			global yes
			yes = True
		if grid[y][x] == 'B':
			global no
			no = True
		if y == n - 1 and x == m - 1:
			global bot
			bot = True
		for (a, b) in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
			if n > y + a >= 0 and m > x + b >= 0 and (not vis[y + a][x + b]) and (grid[y + a][x + b] != '#'):
				q.append((a + y, x + b))
				vis[a + y][x + b] = True
for _ in range(int(input())):
	(n, m) = mi()
	grid = [list(si()) for i in range(n)]
	vis = [[False for i in range(m)] for j in range(n)]
	bad = False
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 'B':
				for (a, b) in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
					if n > i + a >= 0 and m > j + b >= 0:
						if grid[i + a][j + b] == 'G':
							bad = True
						if grid[i + a][j + b] == 'B':
							continue
						grid[i + a][j + b] = '#'
	for i in range(n):
		for j in range(m):
			yes = False
			no = False
			bot = False
			if not vis[i][j] and grid[i][j] != '#':
				bfs(i, j)
			if not bot and yes:
				bad = True
			if bot and no:
				bad = True
	print('No' if bad else 'Yes')


import sys
ii = lambda : sys.stdin.readline().strip()
idata = lambda : [int(x) for x in ii().split()]
sdata = lambda : list(input())

def solve():
	(n, m) = idata()
	data = []
	g = 0
	b = 0
	data1 = []
	for i in range(n):
		s = sdata()
		data1 += [[0] * m]
		data += [s[:]]
		g += s.count('G')
		b += s.count('B')
	if g == 0:
		print('YES')
		return
	if m > 1 and data[-1][-2] == 'B' or (n > 1 and data[-2][-1] == 'B'):
		print('NO')
		return
	dx = [0, 0, -1, 1]
	dy = [1, -1, 0, 0]
	que = [(n - 1, m - 1)]
	while que:
		(x, y) = que.pop(0)
		if data1[x][y] == 0:
			if data[x][y] == '.' or data[x][y] == 'G':
				data1[x][y] = 1
			elif data[x][y] == '#':
				data1[x][y] = -1
			else:
				data1[x][y] = 2
				for k in range(4):
					if 0 <= x + dx[k] < n and 0 <= y + dy[k] < m and (data[x + dx[k]][y + dy[k]] != 'B') and (data[x + dx[k]][y + dy[k]] != 'G'):
						data[x + dx[k]][y + dy[k]] = '#'
			if data[x][y] != '#':
				for k in range(4):
					if 0 <= x + dx[k] < n and 0 <= y + dy[k] < m:
						que += [(x + dx[k], y + dy[k])]
	data2 = []
	for i in range(n):
		data2 += [[0] * m]
	data2[-1][-1] = 13
	que = [(n - 1, m - 1)]
	while que:
		(x, y) = que.pop(0)
		if data2[x][y] == 0:
			if data[x][y] == '.' or data[x][y] == 'B' or data[x][y] == 'G':
				for k in range(4):
					if 0 <= x + dx[k] < n and 0 <= y + dy[k] < m and (data1[x + dx[k]][y + dy[k]] == 1):
						data2[x][y] = 1
				if data2[x][y] == 0:
					data2[x][y] = -1
				for k in range(4):
					if 0 <= x + dx[k] < n and 0 <= y + dy[k] < m:
						que += [(x + dx[k], y + dy[k])]
			elif data[x][y] == '#':
				data2[x][y] = -1
		elif data2[x][y] == 13:
			for k in range(4):
				if 0 <= x + dx[k] < n and 0 <= y + dy[k] < m:
					que += [(x + dx[k], y + dy[k])]
	for i in range(n):
		for j in range(m):
			if data[i][j] == 'B' and data2[i][j] == 1 or (data[i][j] == 'G' and (data2[i][j] == -1 or data2[i][j] == 0)):
				print('NO')
				return
	print('YES')
	return
for t in range(int(ii())):
	solve()


from sys import stdin, stdout
import sys
from math import *
from collections import deque
input = stdin.readline

def bfs(i, j, ar):
	n = len(ar)
	m = len(ar[0]) - 1
	q1 = deque()
	q2 = deque()
	q1.append(i)
	q2.append(j)
	v[i][j] = 1
	while len(q1) > 0:
		x = q1.popleft()
		y = q2.popleft()
		if x < n - 1 and ar[x + 1][y] != '#' and (v[x + 1][y] == 0):
			v[x + 1][y] = 1
			q1.append(x + 1)
			q2.append(y)
		if x > 0 and ar[x - 1][y] != '#' and (v[x - 1][y] == 0):
			v[x - 1][y] = 1
			q1.append(x - 1)
			q2.append(y)
		if y < m - 1 and ar[x][y + 1] != '#' and (v[x][y + 1] == 0):
			v[x][y + 1] = 1
			q1.append(x)
			q2.append(y + 1)
		if y > 0 and ar[x][y - 1] != '#' and (v[x][y - 1] == 0):
			v[x][y - 1] = 1
			q1.append(x)
			q2.append(y - 1)
	return False
for __ in range(int(input())):
	(n, m) = map(int, input().split())
	ar = []
	v = []
	for i in range(n):
		ar.append(list(input()))
		v.append([0] * m)
	for i in range(n):
		for j in range(m):
			if ar[i][j] == 'B':
				if i < n - 1 and ar[i + 1][j] == '.':
					ar[i + 1][j] = '#'
				if i > 0 and ar[i - 1][j] == '.':
					ar[i - 1][j] = '#'
				if j < m - 1 and ar[i][j + 1] == '.':
					ar[i][j + 1] = '#'
				if j > 0 and ar[i][j - 1] == '.':
					ar[i][j - 1] = '#'
	rslt = 0
	if ar[n - 1][m - 1] == '.':
		bfs(n - 1, m - 1, ar)
	for i in range(n):
		for j in range(m):
			if ar[i][j] == 'G':
				ans = v[i][j] == 1
				if ans == False:
					rslt = 1
					break
				else:
					if i < n - 1 and ar[i + 1][j] == 'B':
						rslt = 1
						break
					if i > 0 and ar[i - 1][j] == 'B':
						rslt = 1
						break
					if j < m - 1 and ar[i][j + 1] == 'B':
						rslt = 1
						break
					if j > 0 and ar[i][j - 1] == 'B':
						rslt = 1
						break
		if rslt == 1:
			break
	if rslt == 0:
		print('Yes')
	else:
		print('No')


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

def inar():
	return [int(k) for k in input().split()]

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		ar = []
		for i in range(n):
			ar.append(list(input()))
		for i in range(n):
			for j in range(m):
				if ar[i][j] == 'B':
					if i - 1 >= 0 and ar[i - 1][j] == '.':
						ar[i - 1][j] = '#'
					if i + 1 < n and ar[i + 1][j] == '.':
						ar[i + 1][j] = '#'
					if j - 1 >= 0 and ar[i][j - 1] == '.':
						ar[i][j - 1] = '#'
					if j + 1 < m and ar[i][j + 1] == '.':
						ar[i][j + 1] = '#'
		q = []
		visited = []
		for i in range(n):
			visited.append([False] * m)
		if ar[n - 1][m - 1] == '.':
			q.append((n - 1, m - 1))
			visited[n - 1][m - 1] = True
		while q:
			pos = q.pop()
			i = pos[0]
			j = pos[1]
			if i - 1 >= 0 and ar[i - 1][j] != '#' and (visited[i - 1][j] == False):
				q.append((i - 1, j))
				visited[i - 1][j] = True
			if i + 1 < n and ar[i + 1][j] != '#' and (visited[i + 1][j] == False):
				q.append((i + 1, j))
				visited[i + 1][j] = True
			if j - 1 >= 0 and ar[i][j - 1] != '#' and (visited[i][j - 1] == False):
				q.append((i, j - 1))
				visited[i][j - 1] = True
			if j + 1 < m and ar[i][j + 1] != '#' and (visited[i][j + 1] == False):
				q.append((i, j + 1))
				visited[i][j + 1] = True
		good = True
		for i in range(n):
			for j in range(m):
				if ar[i][j] == 'G' and visited[i][j] == False or (ar[i][j] == 'B' and visited[i][j] == True):
					good = False
					break
		if good:
			print('Yes')
		else:
			print('No')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
ipnl = lambda n: [int(input()) for _ in range(n)]
inp = lambda : int(input())
ip = lambda : [int(w) for w in input().split()]
for _ in range(inp()):
	(n, m) = ip()
	x = []
	gc = 0
	(dx, dy) = ([1, -1, 0, 0], [0, 0, -1, 1])
	for i in range(n):
		t = list(input())
		gc += t.count('G')
		x.append(t)
	if gc == 0:
		print('Yes')
		continue
	flag = 0
	for i in range(n):
		for j in range(m):
			if x[i][j] == 'B':
				for k in range(4):
					(nx, ny) = (i + dx[k], j + dy[k])
					if 0 <= nx < n and 0 <= ny < m:
						if x[nx][ny] == '.':
							x[nx][ny] = '#'
						elif x[nx][ny] == 'G':
							flag = 1
							break
				if flag:
					break
		if flag:
			break
	if flag:
		print('No')
		continue
	gset = set()
	vis = set()
	q = [(n - 1, m - 1)]
	vis.add((n - 1, m - 1))
	while q:
		(i, j) = q.pop(0)
		if x[i][j] in ['#', 'B']:
			continue
		if x[i][j] == 'G':
			gset.add((i, j))
		for k in range(4):
			(nx, ny) = (i + dx[k], j + dy[k])
			if 0 <= nx < n and 0 <= ny < m:
				if (nx, ny) not in vis:
					vis.add((nx, ny))
					q.append((nx, ny))
	if len(gset) == gc:
		print('Yes')
	else:
		print('No')


import sys
sys.setrecursionlimit(10 ** 5)
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [list(input()) for _ in range(n)]
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'B':
				if i > 0 and a[i - 1][j] == '.':
					a[i - 1][j] = '#'
				if i < n - 1 and a[i + 1][j] == '.':
					a[i + 1][j] = '#'
				if j > 0 and a[i][j - 1] == '.':
					a[i][j - 1] = '#'
				if j < m - 1 and a[i][j + 1] == '.':
					a[i][j + 1] = '#'
	vis = [[False] * m for _ in range(n)]

	def dfs(i, j):
		if 0 <= i < n and 0 <= j < m and (a[i][j] != '#'):
			if vis[i][j]:
				return
			vis[i][j] = True
			dfs(i - 1, j)
			dfs(i, j - 1)
			dfs(i + 1, j)
			dfs(i, j + 1)
	dfs(n - 1, m - 1)
	ans = 'Yes'
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'G':
				if not vis[i][j]:
					ans = 'No'
			if a[i][j] == 'B':
				if vis[i][j]:
					ans = 'No'
	print(ans)


from sys import stdin
from collections import deque
tt = int(stdin.readline())
for loop in range(tt):
	(n, m) = map(int, stdin.readline().split())
	a = []
	for i in range(n):
		tmp = stdin.readline()
		a.append(list(tmp[:-1]))
	flag = True
	goodnum = 0
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'B':
				if i != 0 and a[i - 1][j] == '.':
					a[i - 1][j] = '#'
				if i != n - 1 and a[i + 1][j] == '.':
					a[i + 1][j] = '#'
				if j != 0 and a[i][j - 1] == '.':
					a[i][j - 1] = '#'
				if j != m - 1 and a[i][j + 1] == '.':
					a[i][j + 1] = '#'
				if i != 0 and a[i - 1][j] == 'G':
					flag = False
				if i != n - 1 and a[i + 1][j] == 'G':
					flag = False
				if j != 0 and a[i][j - 1] == 'G':
					flag = False
				if j != m - 1 and a[i][j + 1] == 'G':
					flag = False
			elif a[i][j] == 'G':
				goodnum += 1
	if not flag or a[-1][-1] == '#':
		if goodnum == 0:
			print('Yes')
		else:
			print('No')
		continue
	able = [[True] * m for i in range(n)]
	q = deque([(n - 1, m - 1)])
	able[-1][-1] = False
	ngood = 0
	while len(q) > 0:
		(x, y) = q.popleft()
		if a[x][y] == 'G':
			ngood += 1
		i = x
		j = y
		if x != 0 and a[i - 1][j] != '#' and able[i - 1][j]:
			able[i - 1][j] = False
			q.append((i - 1, j))
		if x != n - 1 and a[i + 1][j] != '#' and able[i + 1][j]:
			able[i + 1][j] = False
			q.append((i + 1, j))
		if y != 0 and a[i][j - 1] != '#' and able[i][j - 1]:
			able[i][j - 1] = False
			q.append((i, j - 1))
		if y != m - 1 and a[i][j + 1] != '#' and able[i][j + 1]:
			able[i][j + 1] = False
			q.append((i, j + 1))
	if ngood == goodnum:
		print('Yes')
	else:
		print('No')


def main():
	T = int(input())
	for _ in range(T):
		(N, M) = map(int, input().split())
		A = []
		for _ in range(N):
			A.append(list(input()))
		for i in range(N):
			for j in range(M):
				if A[i][j] == 'B':
					if i - 1 >= 0:
						if A[i - 1][j] == '.':
							A[i - 1][j] = '#'
					if i + 1 < N:
						if A[i + 1][j] == '.':
							A[i + 1][j] = '#'
					if j - 1 >= 0:
						if A[i][j - 1] == '.':
							A[i][j - 1] = '#'
					if j + 1 < M:
						if A[i][j + 1] == '.':
							A[i][j + 1] = '#'
		visited = [[False for i in range(M)] for j in range(N)]
		if A[N - 1][M - 1] == '.':
			queue = [(N - 1, M - 1)]
			visited[N - 1][M - 1] = True
			while queue != []:
				first = queue[0]
				queue.pop(0)
				(i, j) = (first[0], first[1])
				if i - 1 >= 0:
					if A[i - 1][j] != '#' and visited[i - 1][j] == False:
						queue.append((i - 1, j))
						visited[i - 1][j] = True
				if i + 1 < N:
					if A[i + 1][j] != '#' and visited[i + 1][j] == False:
						queue.append((i + 1, j))
						visited[i + 1][j] = True
				if j - 1 >= 0:
					if A[i][j - 1] != '#' and visited[i][j - 1] == False:
						queue.append((i, j - 1))
						visited[i][j - 1] = True
				if j + 1 < M:
					if A[i][j + 1] != '#' and visited[i][j + 1] == False:
						queue.append((i, j + 1))
						visited[i][j + 1] = True
		escapePossibility = True
		for i in range(N):
			for j in range(M):
				if A[i][j] == 'G' and visited[i][j] == False or (A[i][j] == 'B' and visited[i][j] == True):
					escapePossibility = False
					break
			if not escapePossibility:
				break
		if escapePossibility:
			print('Yes')
		else:
			print('No')
main()


import math
from collections import defaultdict

def r():
	return int(input())

def rm():
	return map(int, input().split())

def rl():
	return list(map(int, input().split()))
dir = [[0, 1], [0, -1], [1, 0], [-1, 0]]

def valid(i, j, n, m):
	return i >= 0 and i < n and (j >= 0) and (j < m)
for _ in range(r()):
	(n, m) = rm()
	li = []
	for i in range(n):
		li.append(list(input()))
	for i in range(n):
		for j in range(m):
			if li[i][j] == 'B':
				for k in dir:
					ki = i + k[0]
					kj = j + k[1]
					if valid(ki, kj, n, m):
						if li[ki][kj] == '.':
							li[ki][kj] = '#'
	queue = []
	visited = defaultdict(bool)
	if li[n - 1][m - 1] == '.':
		queue.append((n - 1, m - 1))
		visited[n - 1, m - 1] = True
	while queue:
		(i, j) = queue.pop(0)
		visited[i, j] = True
		for k in dir:
			(ni, nj) = (i + k[0], j + k[1])
			if valid(ni, nj, n, m):
				if not visited[ni, nj] and li[ni][nj] != '#':
					queue.append((ni, nj))
				visited[ni, nj] = True
	good = True
	for i in range(n):
		for j in range(m):
			if li[i][j] == 'G' and (not visited[i, j]) or (li[i][j] == 'B' and visited[i, j]):
				good = False
				break
	if good:
		print('Yes')
	else:
		print('No')


import sys
sys.setrecursionlimit(10000)
R = lambda : map(int, input().split())

def findGoods(grid, visited, i, j):
	dr = [-1, 1, 0, 0]
	dc = [0, 0, 1, -1]
	visited[i][j] = True
	result = 0
	for d in range(4):
		(ni, nc) = (i + dr[d], j + dc[d])
		if (0 <= ni < len(grid) and 0 <= nc < len(grid[0])) and (not visited[ni][nc]):
			if grid[ni][nc] == '#':
				continue
			elif grid[ni][nc] == 'G':
				result += 1
			elif grid[ni][nc] == 'B':
				return -100000
			result += findGoods(grid, visited, ni, nc)
	return result

def bfs(grid, i, j):
	dr = [-1, 1, 0, 0]
	dc = [0, 0, 1, -1]
	for d in range(4):
		(ni, nc) = (i + dr[d], j + dc[d])
		if 0 <= ni < len(grid) and 0 <= nc < len(grid[0]):
			if grid[ni][nc] == '.':
				grid[ni][nc] = '#'
T = int(input())
for t in range(T):
	(n, m) = R()
	grid = []
	bads = []
	goods = 0
	for i in range(n):
		line = input()
		grid.append(list(line))
	for (i, line) in enumerate(grid):
		for (j, cell) in enumerate(line):
			if cell == 'B':
				bads.append((i, j))
			elif cell == 'G':
				goods += 1
	for (x, y) in bads:
		bfs(grid, x, y)
	visited = list(([False] * m for _ in range(n)))
	escapable = findGoods(grid, visited, n - 1, m - 1)
	print('YES' if escapable == goods or goods == 0 else 'NO')


from collections import deque

def valid(i, j):
	return 0 <= i <= n - 1 and 0 <= j <= m - 1
dir = [[1, 0], [-1, 0], [0, 1], [0, -1]]
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = [input() for __ in range(n)]
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'B':
				for k in range(4):
					ni = i + dir[k][0]
					nj = j + dir[k][1]
					if valid(ni, nj) and arr[ni][nj] == '.':
						arr[ni] = arr[ni][:nj] + '#' + arr[ni][nj + 1:]
	queue = deque([])
	visited = [[False for j in range(m)] for i in range(n)]
	if arr[n - 1][m - 1] == '.':
		queue.append([n - 1, m - 1])
		visited[n - 1][m - 1] = True
	while queue:
		curr = queue.popleft()
		for k in range(4):
			ni = curr[0] + dir[k][0]
			nj = curr[1] + dir[k][1]
			if valid(ni, nj) and arr[ni][nj] != '#' and (not visited[ni][nj]):
				queue.append([ni, nj])
				visited[ni][nj] = True
	good = True
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'G' and (not visited[i][j]) or (arr[i][j] == 'B' and visited[i][j]):
				good = False
				break
	print('Yes' if good else 'No')


import os
inp = os.read(0, os.fstat(0).st_size).split(b'\n')
_ii = -1

def rdln():
	global _ii
	_ii += 1
	return inp[_ii]
inin = lambda typ=int: typ(rdln())
inar = lambda typ=int: [typ(x) for x in rdln().split()]
inst = lambda : rdln().strip().decode()
from types import GeneratorType

def recursive(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
(n, m) = (0, 0)
maze = []
dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]

@recursive
def dfs(i, j, visited):
	visited[i][j] = True
	for delta in range(4):
		x = j + dx[delta]
		y = i + dy[delta]
		if x >= 0 and y >= 0 and (x < m) and (y < n) and (visited[y][x] == False):
			if maze[y][x] == '.' or maze[y][x] == 'G':
				yield dfs(y, x, visited)
	yield
Gloc = []
Testcase = inin()
for _ in range(Testcase):
	Gloc = []
	(n, m) = inar()
	maze = ['' for i in range(n)]
	for i in range(n):
		maze[i] = list(inst())
	pasapasi = False
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'G':
				Gloc.append((i, j))
			if maze[i][j] == 'B':
				for delta in range(4):
					x = j + dx[delta]
					y = i + dy[delta]
					if x >= 0 and y >= 0 and (x < m) and (y < n):
						if maze[y][x] == 'G':
							pasapasi = True
							break
						if maze[y][x] == '.':
							maze[y][x] = '#'
	if pasapasi:
		print('No')
	elif maze[n - 1][m - 1] == '#':
		if Gloc == []:
			print('Yes')
		else:
			print('No')
	else:
		visited = [[False for j in range(m)] for i in range(n)]
		dfs(n - 1, m - 1, visited)
		cond = True
		for (i, j) in Gloc:
			cond = cond and visited[i][j]
		if cond:
			print('Yes')
		else:
			print('No')


from bisect import bisect_right
import sys
sys.setrecursionlimit(10000)

def findPossible(start):
	theno = start[1] + start[0] * m
	try:
		hey = possible2[theno]
		return
	except:
		possible2[theno] = 1
	if start[0] != 0 and a[start[0] - 1][start[1]] != '#':
		findPossible([start[0] - 1, start[1]])
	if start[1] != 0 and a[start[0]][start[1] - 1] != '#':
		findPossible([start[0], start[1] - 1])
	if start[0] != n - 1 and a[start[0] + 1][start[1]] != '#':
		findPossible([start[0] + 1, start[1]])
	if start[1] != m - 1 and a[start[0]][start[1] + 1] != '#':
		findPossible([start[0], start[1] + 1])
t = int(input())
for _ in range(t):
	try:
		(n, m) = input().split()
		n = int(n)
		m = int(m)
		a = []
		G = []
		B = []
		for i in range(n):
			b = input()
			a.append(list(b))
			for j in range(len(b)):
				if b[j] == 'G':
					G.append([i, j])
				if b[j] == 'B':
					B.append([i, j])
		for point in B:
			if point[0] != 0:
				a[point[0] - 1][point[1]] = '#'
			if point[1] != 0:
				a[point[0]][point[1] - 1] = '#'
			if point[0] != n - 1:
				a[point[0] + 1][point[1]] = '#'
			if point[1] != m - 1:
				a[point[0]][point[1] + 1] = '#'
		possible2 = {}
		start = [n - 1, m - 1]
		if a[n - 1][m - 1] == '#':
			if len(G) == 0:
				print('Yes')
			else:
				print('No')
		else:
			findPossible(start)
			sed = 0
			for good in G:
				theno = good[1] + good[0] * m
				try:
					x = possible2[theno]
				except:
					sed = 1
					break
			if sed == 0:
				print('Yes')
			else:
				print('No')
	except Exception as e:
		print(str(e) + 'hi')


def ckgd(A, i, j, n, m):
	if i > 0:
		if A[i - 1][j] == 'G':
			return 0
		if A[i - 1][j] == '.':
			A[i - 1][j] = '#'
	if j > 0:
		if A[i][j - 1] == 'G':
			return 0
		if A[i][j - 1] == '.':
			A[i][j - 1] = '#'
	if i < n - 1:
		if A[i + 1][j] == 'G':
			return 0
		if A[i + 1][j] == '.':
			A[i + 1][j] = '#'
	if j < m - 1:
		if A[i][j + 1] == 'G':
			return 0
		if A[i][j + 1] == '.':
			A[i][j + 1] = '#'
T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	A = []
	for i in range(n):
		A.append(list(input()))
	f = 1
	for i in range(n):
		for j in range(m):
			if A[i][j] == 'B':
				if ckgd(A, i, j, n, m) == 0:
					f = 0
					break
		if f == 0:
			break
	if f == 0:
		print('No')
	else:
		B = [[0 for i in range(m)] for j in range(n)]
		Q = []
		if A[n - 1][m - 1] != '#':
			Q = [[n - 1, m - 1]]
			vis = [[0 for i in range(m)] for j in range(n)]
			B[n - 1][m - 1] = 'E'
		while len(Q) != 0:
			a = Q.pop()
			i = a[0]
			j = a[1]
			vis[i][j] = 1
			if i > 0 and A[i - 1][j] != '#' and (vis[i - 1][j] == 0):
				B[i - 1][j] = 'E'
				Q.append([i - 1, j])
			if j > 0 and A[i][j - 1] != '#' and (vis[i][j - 1] == 0):
				B[i][j - 1] = 'E'
				Q.append([i, j - 1])
			if i < n - 1 and A[i + 1][j] != '#' and (vis[i + 1][j] == 0):
				B[i + 1][j] = 'E'
				Q.append([i + 1, j])
			if j < m - 1 and A[i][j + 1] != '#' and (vis[i][j + 1] == 0):
				B[i][j + 1] = 'E'
				Q.append([i, j + 1])
		f = 1
		for i in range(n):
			for j in range(m):
				if A[i][j] == 'G' and (B[i][j] != 'E' or A[n - 1][m - 1] == '#'):
					f = 0
					break
				elif A[i][j] == 'B' and B[i][j] == 'E':
					f = 0
					break
			if f == 0:
				break
		if f == 0:
			print('No')
		else:
			print('Yes')


def corr(x, y):
	if 0 <= x < n and 0 <= y < m:
		return True
	return False
ans = []
dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	u = []
	for i in range(n):
		u.append(list(input()))
	ok = False
	ex_G = False
	for i in range(n):
		for j in range(m):
			if u[i][j] == 'G':
				ex_G = True
			if u[i][j] != 'B':
				continue
			for k in range(4):
				(xi, yi) = (i + dx[k], j + dy[k])
				if not corr(xi, yi):
					continue
				if u[xi][yi] == 'G':
					ok = True
					break
				if u[xi][yi] == 'B':
					continue
				u[xi][yi] = '#'
			if ok:
				break
		if ok:
			break
	if ok:
		ans.append('NO')
		continue
	if not ex_G:
		ans.append('YES')
		continue
	if u[n - 1][m - 1] == '#':
		ans.append('NO')
		continue
	d = []
	for i in range(n):
		d.append([0] * m)
	d[n - 1][m - 1] = 1
	q = [(n - 1, m - 1)]
	q0 = 0
	while len(q) > q0:
		(x, y) = q[q0]
		q0 += 1
		for k in range(4):
			(xi, yi) = (x + dx[k], y + dy[k])
			if not corr(xi, yi) or d[xi][yi] == 1 or u[xi][yi] == '#':
				continue
			d[xi][yi] = 1
			q.append((xi, yi))
	ok_ans = False
	for i in range(n):
		for j in range(m):
			if u[i][j] == 'G' and d[i][j] == 0:
				ok_ans = True
				break
		if ok_ans:
			break
	if ok_ans:
		ans.append('NO')
	else:
		ans.append('YES')
print('\n'.join(map(str, ans)))


import sys
from collections import deque
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	grid = []
	bad = []
	good = 0
	for i in range(n):
		line = list(input())
		for j in range(m):
			if line[j] == 'G':
				good += 1
			elif line[j] == 'B':
				bad.append((i, j))
		grid.append(line)
	for (i, j) in bad:
		pos = [(0, 1), (0, -1), (1, 0), (-1, 0)]
		for (a, b) in pos:
			(x, y) = (i + a, j + b)
			if 0 <= x < n and 0 <= y < m:
				grid[x][y] = '#'
	queue = deque([(n - 1, m - 1)])
	if not good:
		print('Yes')
		continue
	if grid[n - 1][m - 1] == '#':
		print('No')
		continue
	while queue:
		(i, j) = queue.popleft()
		pos = [(0, 1), (0, -1), (1, 0), (-1, 0)]
		for (a, b) in pos:
			(x, y) = (i + a, j + b)
			if 0 <= x < n and 0 <= y < m:
				if grid[x][y] != '#':
					if grid[x][y] == 'G':
						good -= 1
					grid[x][y] = '#'
					queue.append((x, y))
	if not good:
		print('Yes')
	else:
		print('No')


from collections import defaultdict
import math
from functools import reduce
from heapq import heapify, heappush, heappop
import sys
from sys import stdin, stdout
from random import seed
from random import randint
mod = 10 ** 9 + 7

def mul_mod(a, b):
	return a % mod * (b % mod) % mod

def add_mod(a, b):
	return (a % mod + b % mod) % mod

def sub_mod(a, b):
	return (a % mod - b % mod + mod) % mod

def modInverse(b):
	return pow(b, mod - 2, mod)

def div_mod(a, b):
	a = a % mod
	inv = modInverse(b)
	return inv * a % mod

class Graph:

	def __init__(self, vertices):
		self.V = vertices + 1
		self.graph = defaultdict(set)
		self.Time = 0
		self.P = 0
		self.Q = 0

	def addEdge(self, u, v):
		self.graph[u].add(v)
		self.graph[v].add(u)

	def bridgeUtil(self, u):
		self.count[u] += 1
		self.disc[u] = self.Time
		self.low[u] = self.Time
		self.Time += 1
		for v in self.graph[u]:
			if self.count[v] == 0:
				self.parent[v] = u
				self.bridgeUtil(v)
				self.count[u] += self.count[v]
				self.low[u] = min(self.low[u], self.low[v])
				if self.low[v] > self.disc[u]:
					self.Q += 1
					if self.count[v] % 2 == 0:
						self.P += 1
			elif v != self.parent[u]:
				self.low[u] = min(self.low[u], self.disc[v])

	def bridge(self):
		self.disc = [float('Inf')] * self.V
		self.low = [float('Inf')] * self.V
		self.parent = [-1] * self.V
		self.count = [0] * self.V
		for i in range(1, self.V):
			if self.count[i] == 0:
				self.bridgeUtil(i)
move_x = [1, -1, 0, 0]
move_y = [0, 0, 1, -1]
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	mat = []
	for i in range(n):
		mat.append(list(input()))
	count_G = 0
	count_B = 0
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 'G':
				count_G += 1
			elif mat[i][j] == 'B':
				count_B += 1
	if count_G == 0:
		print('Yes')
		continue
	adjacent = False
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 'G':
				for k in range(4):
					new_i = i + move_x[k]
					new_j = j + move_y[k]
					if 0 <= new_i < n and 0 <= new_j < m and (mat[new_i][new_j] == 'B'):
						adjacent = True
						break
			if adjacent:
				break
		if adjacent:
			break
	if adjacent:
		print('No')
		continue
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 'B':
				for k in range(4):
					new_i = i + move_x[k]
					new_j = j + move_y[k]
					if 0 <= new_i < n and 0 <= new_j < m and (mat[new_i][new_j] != 'B'):
						mat[new_i][new_j] = '#'
	if mat[-1][-1] == '#':
		print('No')
		continue
	visited = [[False for j in range(m)] for i in range(n)]
	reachable = 0
	curr = [(n - 1, m - 1)]
	visited[n - 1][m - 1] = True
	l = 0
	idx = 0
	while l < len(curr):
		l = len(curr)
		while idx < l:
			(i, j) = curr[idx]
			idx += 1
			if mat[i][j] == 'G':
				reachable += 1
			for k in range(4):
				new_i = i + move_x[k]
				new_j = j + move_y[k]
				if 0 <= new_i < n and 0 <= new_j < m and (mat[new_i][new_j] != '#') and (not visited[new_i][new_j]):
					visited[new_i][new_j] = True
					curr.append((new_i, new_j))
	if count_G == reachable:
		print('Yes')
	else:
		print('No')


t = int(input())
dX = [1, -1, 0, 0]
dY = [0, 0, -1, 1]
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	l = []
	for i in range(n):
		l.append(list(input().strip()))
	gCount = 0
	for i in range(n):
		for j in range(m):
			if l[i][j] == 'G':
				gCount += 1
			elif l[i][j] == 'B':
				for d in range(4):
					x = i + dX[d]
					y = j + dY[d]
					if 0 <= x < n and 0 <= y < m and (l[x][y] == '.'):
						l[x][y] = '#'
	visited = [[False] * m for i in range(n)]
	gVisit = 0
	stack = []
	if l[n - 1][m - 1] != '#':
		stack.append((n - 1, m - 1))
		visited[n - 1][m - 1] = True
	works = True
	while stack:
		(nexX, nexY) = stack.pop()
		c = l[nexX][nexY]
		if c == 'G':
			gVisit += 1
		elif c == 'B':
			works = False
			break
		for d in range(4):
			x = nexX + dX[d]
			y = nexY + dY[d]
			if 0 <= x < n and 0 <= y < m and (l[x][y] != '#') and (not visited[x][y]):
				visited[x][y] = True
				stack.append((x, y))
	if works and gVisit == gCount:
		print('Yes')
	else:
		print('No')


from collections import deque
t = int(input())
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
for _ in range(t):
	(n, m) = map(int, input().split())
	l = [list(input()) for i in range(n)]
	count = 0
	for i in l:
		count += i.count('G')
	if count == 0:
		print('Yes')
		continue
	used = [[0] * m for i in range(n)]
	check = True
	for i in range(n):
		for j in range(m):
			if l[i][j] == 'B':
				q = deque([])
				q.append((i, j))
				used[i][j] = 1
				while q:
					(x, y) = q.popleft()
					for k in range(4):
						nx = x + dx[k]
						ny = y + dy[k]
						if 0 <= nx < n and 0 <= ny < m:
							if l[nx][ny] == '.':
								l[nx][ny] = '#'
								continue
							if l[nx][ny] == 'G':
								check = False
								break
							if l[nx][ny] == 'B' and (not used[nx][ny]):
								used[nx][ny] = 1
								q.append((nx, ny))
	if check == False or l[-1][-1] == '#':
		print('No')
		continue
	used = [[0] * m for i in range(n)]
	q = deque([])
	q.append((n - 1, m - 1))
	used[-1][-1] = 1
	while q:
		(x, y) = q.popleft()
		for k in range(4):
			nx = x + dx[k]
			ny = y + dy[k]
			if 0 <= nx < n and 0 <= ny < m:
				if l[nx][ny] == '.' or l[nx][ny] == 'G':
					if used[nx][ny]:
						continue
					used[nx][ny] = 1
					q.append((nx, ny))
	for i in range(n):
		for j in range(m):
			if l[i][j] == 'G' and (not used[i][j]):
				check = False
				break
	if check:
		print('Yes')
	else:
		print('No')


t = int(input())
for tc in range(t):
	(n, m) = [int(x) for x in input().split()]
	mat = []
	for i in range(n):
		s = list(input())
		mat.append(s)
	count = 0
	b = 0
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 'G':
				count += 1
	if count == 0:
		print('Yes')
		continue
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 'B':
				if i + 1 < n:
					if mat[i + 1][j] == '.':
						mat[i + 1][j] = '#'
				if i - 1 >= 0:
					if mat[i - 1][j] == '.':
						mat[i - 1][j] = '#'
				if j - 1 >= 0:
					if mat[i][j - 1] == '.':
						mat[i][j - 1] = '#'
				if j + 1 < m:
					if mat[i][j + 1] == '.':
						mat[i][j + 1] = '#'
	dp = [[1 for i in range(m)] for j in range(n)]
	if dp[n - 1][m - 1] == '#':
		print('No')
		continue
	a = []
	b = []
	a.append((n - 1, m - 1))
	while len(a) != 0:
		b = []
		for i in range(len(a)):
			c = a[i][0]
			d = a[i][1]
			if c + 1 < n and d < m and (dp[c + 1][d] == 1) and (mat[c + 1][d] != '#'):
				b.append((c + 1, d))
				dp[c + 1][d] = 0
			if c < n and d + 1 < m and (dp[c][d + 1] == 1) and (mat[c][d + 1] != '#'):
				b.append((c, d + 1))
				dp[c][d + 1] = 0
			if c - 1 >= 0 and d < m and (dp[c - 1][d] == 1) and (mat[c - 1][d] != '#'):
				b.append((c - 1, d))
				dp[c - 1][d] = 0
			if c >= 0 and d - 1 >= 0 and (dp[c][d - 1] == 1) and (mat[c][d - 1] != '#'):
				b.append((c, d - 1))
				dp[c][d - 1] = 0
		a = b + []
		b = []
	flag = 0
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 'G' and dp[i][j] == 1:
				flag = 1
				break
			if mat[i][j] == 'B' and dp[i][j] == 0:
				flag = 1
				break
	if flag == 1:
		print('No')
	else:
		print('Yes')


from collections import deque

def solve():
	(n, m) = map(int, input().split(' '))
	matrix = []
	for _ in range(n):
		matrix.append(list(input()))
	n_good = 0
	directions = [(0, 1), (0, -1), (1, 0), (-1, 0)]
	for i in range(n):
		for j in range(m):
			if matrix[i][j] == 'G':
				n_good += 1
			elif matrix[i][j] == 'B':
				for (di, dj) in directions:
					if di + i < 0 or di + i >= n or dj + j < 0 or (dj + j >= m) or (matrix[di + i][dj + j] == 'B'):
						continue
					elif matrix[di + i][dj + j] == 'G':
						return 'No'
					matrix[di + i][dj + j] = '#'
	if n_good == 0:
		return 'Yes'
	if matrix[n - 1][m - 1] == '#':
		return 'No'
	q = deque()
	q.append((n - 1, m - 1))
	matrix[n - 1][m - 1] = '#'
	while q:
		(i, j) = q.popleft()
		for (di, dj) in directions:
			if di + i < 0 or di + i >= n or dj + j < 0 or (dj + j >= m) or (matrix[di + i][dj + j] == '#'):
				continue
			if matrix[di + i][dj + j] == 'G':
				n_good -= 1
			matrix[di + i][dj + j] = '#'
			q.append((di + i, dj + j))
	return 'Yes' if n_good == 0 else 'No'
T = int(input())
for _ in range(T):
	print(solve())


import collections
import heapq

def read():
	return input().strip()

def readInt():
	return int(input().strip())

def readList():
	return list(map(int, input().strip().split()))

def solve(n, m, grid):
	for x in range(n):
		for y in range(m):
			if grid[x][y] == 'B':
				for (delX, delY) in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
					(newX, newY) = (x + delX, y + delY)
					if 0 <= newX < n and 0 <= newY < m and (grid[newX][newY] == '.'):
						grid[newX][newY] = '#'
	queue = collections.deque([])
	visited = set()
	if grid[n - 1][m - 1] == '.':
		queue.append((n - 1, m - 1))
		visited.add((n - 1, m - 1))
	while queue:
		(x, y) = queue.popleft()
		for (delX, delY) in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
			(newX, newY) = (x + delX, y + delY)
			if 0 <= newX < n and 0 <= newY < m and (grid[newX][newY] != '#') and ((newX, newY) not in visited):
				visited.add((newX, newY))
				queue.append((newX, newY))
	for x in range(n):
		for y in range(m):
			if grid[x][y] == 'G' and (x, y) not in visited or (grid[x][y] == 'B' and (x, y) in visited):
				return False
	return True
t = readInt()
for i in range(t):
	[n, m] = readList()
	grid = []
	for _ in range(n):
		grid.append([ch for ch in read()])
	print('Yes' if solve(n, m, grid) else 'No')


from collections import defaultdict as dd
from collections import deque
import bisect
import heapq

def ri():
	return int(input())

def rl():
	return list(map(int, input().split()))

def nbrs(i, j, r, c):
	if i > 0:
		yield (i - 1, j)
	if i < r - 1:
		yield (i + 1, j)
	if j > 0:
		yield (i, j - 1)
	if j < c - 1:
		yield (i, j + 1)
	return

def solve():
	(rows, cols) = rl()
	grid = []
	for i in range(rows):
		grid.append(list(input()))
	if grid[rows - 1][cols - 1] == 'B':
		print('No')
		return
	goods = 0
	for i in range(rows):
		for j in range(cols):
			if grid[i][j] == 'B':
				for nbr in nbrs(i, j, rows, cols):
					(x, y) = nbr
					if grid[x][y] == 'G':
						print('No')
						return
					elif grid[x][y] == '.':
						grid[x][y] = '#'
			elif grid[i][j] == 'G':
				goods += 1
	if goods == 0:
		print('Yes')
		return
	elif grid[rows - 1][cols - 1] == '#':
		print('No')
		return
	curr = [(rows - 1, cols - 1)]
	seen = set(curr)
	while curr:
		nxt = []
		for pair in curr:
			for nbr in nbrs(*pair, rows, cols):
				(x, y) = nbr
				if grid[x][y] not in ['.', 'G']:
					continue
				if nbr not in seen:
					seen.add(nbr)
					nxt.append(nbr)
					if grid[nbr[0]][nbr[1]] == 'G':
						goods -= 1
		curr = nxt
	if goods == 0:
		print('Yes')
	else:
		print('No')
mode = 'T'
if mode == 'T':
	t = ri()
	for i in range(t):
		solve()
else:
	solve()


import sys
input = lambda : sys.stdin.readline().rstrip()
mod = 10 ** 9 + 7
t = int(input())
from collections import deque

def bfs(x, y):
	d = [[-1] * m for _ in range(n)]
	queue = deque([(x, y)])
	d[x][y] = 0
	while queue:
		(x, y) = queue.popleft()
		next_grid = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
		for (u, v) in next_grid:
			if not (0 <= u < n and 0 <= v < m) or d[u][v] >= 0:
				continue
			if g[u][v] == '#' or g[u][v] == 'B':
				continue
			next_next_grid = [(u + 1, v), (u - 1, v), (u, v + 1), (u, v - 1)]
			flag = 1
			for (p, q) in next_next_grid:
				if not (0 <= p < n and 0 <= q < m):
					continue
				if g[p][q] == 'B':
					flag = 0
					break
			if flag:
				d[u][v] = d[x][y] + 1
				queue.append((u, v))
	return d
for _ in range(t):
	(n, m) = map(int, input().split())
	g = []
	good = []
	for i in range(n):
		temp = input()
		g.append(temp)
		for j in range(m):
			if temp[j] == 'G':
				good.append((i, j))
	if len(good) == 0:
		print('Yes')
		continue
	(x, y) = good[0]
	next_grid = [(x + 1, y), (x - 1, y), (x, y + 1), (x, y - 1)]
	flag = 1
	for (u, v) in next_grid:
		if not (0 <= u < n and 0 <= v < m):
			continue
		if g[u][v] == 'B':
			print('No')
			flag = 0
			break
	if not flag:
		continue
	d = bfs(x, y)
	if d[n - 1][m - 1] < 0:
		print('No')
		continue
	for (x, y) in good:
		if d[x][y] < 0:
			print('No')
			flag = 0
			break
	if flag:
		print('Yes')


def bfs(c, l, n, m):
	queue = [(n - 1, m - 1)]
	while queue:
		i = queue.pop()
		if l[i[0]][i[1]] == 'G':
			c -= 1
		if i[1] != m - 1 and l[i[0]][i[1]] != '#':
			queue.append((i[0], i[1] + 1))
		if i[1] != 0 and l[i[0]][i[1]] != '#':
			queue.append((i[0], i[1] - 1))
		if i[0] != n - 1 and l[i[0]][i[1]] != '#':
			queue.append((i[0] + 1, i[1]))
		if i[0] != 0 and l[i[0]][i[1]] != '#':
			queue.append((i[0] - 1, i[1]))
		l[i[0]][i[1]] = '#'
	return not c
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = [list(input()) for i in range(n)]
	f = True
	c = 0
	for i in range(n):
		if not f:
			break
		for j in range(m):
			if l[i][j] == 'G':
				c += 1
			elif l[i][j] == 'B':
				if j != m - 1 and l[i][j + 1] == '.':
					l[i][j + 1] = '#'
				elif j != m - 1 and l[i][j + 1] == 'G':
					f = False
					break
				if j != 0 and l[i][j - 1] == '.':
					l[i][j - 1] = '#'
				elif j != 0 and l[i][j - 1] == 'G':
					f = False
					break
				if i != n - 1 and l[i + 1][j] == '.':
					l[i + 1][j] = '#'
				elif i != n - 1 and l[i + 1][j] == 'G':
					f = False
					break
				if i != 0 and l[i - 1][j] == '.':
					l[i - 1][j] = '#'
				elif i != 0 and l[i - 1][j] == 'G':
					f = False
					break
	if f and bfs(c, l, n, m):
		print('YES')
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys
sys.setrecursionlimit(2500)

def dfs(x):
	v[x] = 1
	for i in adj[x]:
		if not v[i]:
			dfs(i)
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	l = []
	for j in range(n):
		l.append(list(input()))
	(g, b) = (0, 0)
	ans = True
	adj = [[] for j in range(n * m + 1)]
	v = [0] * (n * m + 1)
	l2 = []
	for j in range(n):
		for k in range(m):
			if l[j][k] == 'B':
				b += 1
				l2.append(j * m + k + 1)
				if k != m - 1:
					if l[j][k + 1] == '.':
						l[j][k + 1] = '#'
					if l[j][k + 1] == 'G':
						adj[j * m + k + 1].append(j * m + k + 2)
						adj[j * m + k + 2].append(j * m + k + 1)
				if k != 0:
					if l[j][k - 1] == '.':
						l[j][k - 1] = '#'
					if l[j][k - 1] == 'G':
						adj[j * m + k + 1].append(j * m + k)
						adj[j * m + k].append(j * m + k + 1)
				if j != 0:
					if l[j - 1][k] == '.':
						l[j - 1][k] = '#'
					if l[j - 1][k] == 'G':
						adj[j * m + k + 1].append((j - 1) * m + k + 1)
						adj[(j - 1) * m + k + 1].append(j * m + k + 1)
				if j != n - 1:
					if l[j + 1][k] == '.':
						l[j + 1][k] = '#'
					if l[j + 1][k] == 'G':
						adj[j * m + k + 1].append((j + 1) * m + k + 1)
						adj[(j + 1) * m + k + 1].append(j * m + k + 1)
			if l[j][k] == 'G':
				g += 1
	if g == 0:
		print('Yes')
	else:
		l1 = []
		for j in range(n):
			for k in range(m):
				if l[j][k] == '.' or l[j][k] == 'G':
					if l[j][k] == 'G':
						l1.append(j * m + k + 1)
					if k != m - 1:
						if l[j][k + 1] == '.' or l[j][k + 1] == 'G':
							adj[j * m + k + 1].append(j * m + k + 2)
							adj[j * m + k + 2].append(j * m + k + 1)
					if j != n - 1:
						if l[j + 1][k] == '.' or l[j + 1][k] == 'G':
							adj[j * m + k + 1].append((j + 1) * m + k + 1)
							adj[(j + 1) * m + k + 1].append(j * m + k + 1)
		dfs(l1[0])
		for j in l1:
			if v[j] == 0:
				ans = False
				break
		if v[n * m] == 0:
			ans = False
		for j in l2:
			if v[j] == 1:
				ans = False
				break
		if ans:
			print('Yes')
		else:
			print('No')


import sys
input = sys.stdin.buffer.readline
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
inst = lambda : input().decode().rstrip('\n\r')
INF = float('inf')
from types import GeneratorType

def recursive(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def yes():
	print('Yes')

def no():
	print('No')
(n, m) = (0, 0)
maze = []
dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]

def dfs(i, j, visited):
	visited[i][j] = True
	for delta in range(4):
		x = j + dx[delta]
		y = i + dy[delta]
		if x >= 0 and y >= 0 and (x < m) and (y < n) and (visited[y][x] == False):
			if maze[y][x] == '.' or maze[y][x] == 'G':
				dfs(y, x, visited)

def main():
	Gloc = []
	Testcase = inin()
	for _ in range(Testcase):
		Gloc = []
		global n
		global m
		global maze
		(n, m) = inar()
		maze = ['' for i in range(n)]
		for i in range(n):
			maze[i] = list(input().decode())
		pasapasi = False
		for i in range(n):
			for j in range(m):
				if maze[i][j] == 'G':
					Gloc.append((i, j))
				if maze[i][j] == 'B':
					for delta in range(4):
						x = j + dx[delta]
						y = i + dy[delta]
						if x >= 0 and y >= 0 and (x < m) and (y < n):
							if maze[y][x] == 'G':
								pasapasi = True
								break
							if maze[y][x] == '.':
								maze[y][x] = '#'
		if pasapasi:
			no()
		elif maze[n - 1][m - 1] == '#':
			if Gloc == []:
				yes()
			else:
				no()
		else:
			visited = [[False for j in range(m)] for i in range(n)]
			dfs(n - 1, m - 1, visited)
			cond = True
			for (i, j) in Gloc:
				cond = cond and visited[i][j]
			if cond:
				yes()
			else:
				no()
main()


import os
import sys
from io import BytesIO, IOBase
import threading

def main(n, m, grid):
	delta = [(1, 0), (0, 1), (-1, 0), (0, -1)]
	g_cnt = 0
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 'B':
				for (d_x, d_y) in delta:
					n_x = i + d_x
					n_y = j + d_y
					if 0 <= n_x < n and 0 <= n_y < m:
						if grid[n_x][n_y] == '.':
							grid[n_x][n_y] = '#'
						if grid[n_x][n_y] == 'G':
							return 'No'
			elif grid[i][j] == 'G':
				g_cnt += 1
	q = []
	eg_cnt = 0
	if grid[n - 1][m - 1] != '#':
		q.append((n - 1, m - 1))
	while len(q):
		(x, y) = q.pop()
		if grid[x][y] == 'G':
			eg_cnt += 1
		grid[x][y] = '#'
		for (d_x, d_y) in delta:
			n_x = x + d_x
			n_y = y + d_y
			if 0 <= n_x < n and 0 <= n_y < m and (grid[n_x][n_y] in ('.', 'G')):
				q.append((n_x, n_y))
	if eg_cnt == g_cnt:
		return 'Yes'
	else:
		return 'No'
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	grid = []
	for i in range(n):
		grid.append([c for c in input()])
	print(main(n, m, grid))


def valid(x, y, n, m):
	return x >= 0 and x <= n - 1 and (y >= 0) and (y <= m - 1)
T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		l = list(input())
		arr.append(l)
	neigh = [[0, 1], [0, -1], [1, 0], [-1, 0]]
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'B':
				for k in range(4):
					x = i + neigh[k][0]
					y = j + neigh[k][1]
					if valid(x, y, n, m) and arr[x][y] == '.':
						arr[x][y] = '#'
	visited = [[0 for i in range(m)] for j in range(n)]
	que = []
	good = 1
	if arr[n - 1][m - 1] == '.':
		que.append([n - 1, m - 1])
		visited[n - 1][m - 1] = 1
	while len(que):
		curr = que.pop(0)
		for k in range(4):
			x = curr[0] + neigh[k][0]
			y = curr[1] + neigh[k][1]
			if valid(x, y, n, m) and arr[x][y] != '#' and (visited[x][y] != 1):
				visited[x][y] = 1
				que.append([x, y])
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'G' and visited[i][j] != 1 or (arr[i][j] == 'B' and visited[i][j]):
				good = 0
				break
	if good == 1:
		print('Yes')
	else:
		print('No')


import sys
sys.setrecursionlimit(100000)
Directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]

def dfs(i, j):
	if i > n or i == 0 or j > m or (j == 0):
		return
	visited[i][j] = 1
	for (di, dj) in Directions:
		if not visited[i + di][j + dj] and maze[i + di][j + dj] != '#':
			dfs(i + di, j + dj)
for t in range(int(input())):
	(n, m) = list(map(int, input().split()))
	maze = [['#'] * (m + 2)] + [list('#' + input() + '#') for i in range(n)] + [['#'] * (m + 2)]
	visited = [[0] * (m + 2) for i in range(n + 2)]
	canDoIt = True
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if maze[i][j] == 'B':
				for (di, dj) in Directions:
					if maze[i + di][j + dj] == 'G':
						canDoIt = False
					elif maze[i + di][j + dj] != 'B':
						maze[i + di][j + dj] = '#'
	if maze[n][m] != '#':
		dfs(n, m)
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if maze[i][j] == 'G' and (not visited[i][j]):
				canDoIt = False
	print('Yes' if canDoIt else 'No')


import collections
import time
import os
import sys
import bisect
import heapq
from typing import List

def solve(N, M, A):
	good = 0
	for r in range(N):
		for c in range(M):
			if A[r][c] == 'B':
				for (nr, nc) in [(r + 1, c), (r - 1, c), (r, c + 1), (r, c - 1)]:
					if 0 <= nr < N and 0 <= nc < M:
						if A[nr][nc] == 'G':
							return False
						if A[nr][nc] == '.':
							A[nr][nc] = '#'
			elif A[r][c] == 'G':
				good += 1
	if A[N - 1][M - 1] == '#':
		return good == 0
	INF = M * N + 1
	dist = [[INF for _ in range(M)] for _ in range(N)]
	dist[N - 1][M - 1] = 0
	q = collections.deque([(N - 1, M - 1)])
	while q:
		(r, c) = q.popleft()
		for (nr, nc) in [(r + 1, c), (r - 1, c), (r, c + 1), (r, c - 1)]:
			if 0 <= nr < N and 0 <= nc < M and (A[nr][nc] != '#') and (dist[r][c] + 1 < dist[nr][nc]):
				dist[nr][nc] = dist[r][c] + 1
				q.append((nr, nc))
	for r in range(N):
		for c in range(M):
			if A[r][c] == 'G' and dist[r][c] >= INF:
				return False
			if A[r][c] == 'B' and dist[r][c] < INF:
				return False
	return True
T = int(input())
ans = []
for ti in range(T):
	(N, M) = map(int, input().split())
	A = []
	for r in range(N):
		A.append(list(input()))
	ans.append(solve(N, M, A))
print('\n'.join(['YES' if v else 'NO' for v in ans]))


def grid_b(lab, n, m, pos_x, pos_y):
	result = 1
	lab[pos_x][pos_y] = '#'
	if pos_x > 0:
		if lab[pos_x - 1][pos_y] == 'G':
			result = 0
		elif lab[pos_x - 1][pos_y] != 'B':
			lab[pos_x - 1][pos_y] = '#'
	if pos_y > 0:
		if lab[pos_x][pos_y - 1] == 'G':
			result = 0
		elif lab[pos_x][pos_y - 1] != 'B':
			lab[pos_x][pos_y - 1] = '#'
	if pos_x < n - 1:
		if lab[pos_x + 1][pos_y] == 'G':
			result = 0
		elif lab[pos_x + 1][pos_y] != 'B':
			lab[pos_x + 1][pos_y] = '#'
	if pos_y < m - 1:
		if lab[pos_x][pos_y + 1] == 'G':
			result = 0
		elif lab[pos_x][pos_y + 1] != 'B':
			lab[pos_x][pos_y + 1] = '#'
	return result

def find_path(steps, lab, x, y, step):
	if lab[x][y] == '#':
		steps[x][y] = -1
	else:
		steps[x][y] = step
		step += 1
		if x > 0:
			if lab[x - 1][y] != '#' and steps[x - 1][y] == -1:
				find_path(steps, lab, x - 1, y, step)
		if x < n - 1:
			if lab[x + 1][y] != '#' and steps[x + 1][y] == -1:
				find_path(steps, lab, x + 1, y, step)
		if y > 0:
			if lab[x][y - 1] != '#' and steps[x][y - 1] == -1:
				find_path(steps, lab, x, y - 1, step)
		if y < m - 1:
			if lab[x][y + 1] != '#' and steps[x][y + 1] == -1:
				find_path(steps, lab, x, y + 1, step)
tests = int(input())
for i in range(tests):
	numbers = input().split(' ')
	n = int(numbers[0])
	m = int(numbers[1])
	lab = []
	for x in range(n):
		lab.append([])
		line = input()
		for y in range(m):
			lab[x].append(line[y])
	success = 1
	for x in range(n):
		for y in range(m):
			if lab[x][y] == 'B':
				success = grid_b(lab, n, m, x, y)
			if success == 0:
				break
		if success == 0:
			break
	if success == 0:
		print('No')
	else:
		steps = []
		for x in range(n):
			steps.append([])
			for y in range(m):
				steps[x].append(-1)
		find_path(steps, lab, n - 1, m - 1, 0)
		for x in range(n):
			for y in range(m):
				if lab[x][y] == 'G':
					if steps[x][y] == -1:
						success = 0
				if success == 0:
					break
			if success == 0:
				break
		if success == 1:
			print('Yes')
		else:
			print('No')


import sys
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

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

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

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

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
dij = [(1, 0), (0, 1), (-1, 0), (0, -1)]

def main():
	for _ in range(II()):
		(h, w) = MI()
		tt = [list(SI()) for _ in range(h)]
		ng = False
		cntG = 0
		for i in range(h):
			for j in range(w):
				if tt[i][j] == 'G':
					cntG += 1
				if tt[i][j] == 'B':
					for (di, dj) in dij:
						(ni, nj) = (i + di, j + dj)
						if ni < 0 or nj < 0 or ni >= h or (nj >= w):
							continue
						if tt[ni][nj] == 'B':
							continue
						if tt[ni][nj] == 'G':
							ng = True
							continue
						tt[ni][nj] = '#'
		if cntG == 0:
			print('Yes')
			continue
		if ng or tt[h - 1][w - 1] == '#':
			print('No')
			continue
		stack = [(h - 1, w - 1)]
		tt[h - 1][w - 1] = '#'
		while stack:
			(i, j) = stack.pop()
			for (di, dj) in dij:
				(ni, nj) = (i + di, j + dj)
				if ni < 0 or nj < 0 or ni >= h or (nj >= w):
					continue
				if tt[ni][nj] == '#':
					continue
				if tt[ni][nj] == 'G':
					cntG -= 1
				tt[ni][nj] = '#'
				stack.append((ni, nj))
		if cntG == 0:
			print('Yes')
		else:
			print('No')
main()


t = int(input())
ans = ['Yes'] * t
import copy
for times in range(t):
	(Y, X) = map(int, input().split())
	raw = ['#'] + ['.'] * 601 + ['#']
	lastraw = ['#'] * (X + 2)
	field = [['#'] * (X + 2)]
	for i in range(Y):
		s = list(input())
		s.insert(0, '#')
		s.append('#')
		field.append(s)
	field.append(lastraw)
	startqueue = []
	moves = 0
	tests = ((0, 1), (1, 0), (-1, 0), (0, -1))
	if field[Y][X] == 'B':
		moves = -1
	for i in range(1, Y + 1):
		for j in range(1, X + 1):
			if field[i][j] == 'G':
				startqueue.append([i, j])
			elif field[i][j] == 'B':
				for (ny, nx) in tests:
					(ty, tx) = (i + ny, j + nx)
					if field[ty][tx] == 'G':
						moves = -1
					elif field[ty][tx] == '.':
						field[ty][tx] = '#'
				field[i][j] = '#'
	goal_point = (Y + 1, X + 1)
	savedfield = copy.deepcopy(field)
	while True:
		if field[Y][X] == '#' and len(startqueue) != 0:
			moves = -1
		if moves == -1:
			ans[times] = 'No'
			break
		if len(startqueue) == 0:
			break
		[sy, sx] = [Y, X]
		[gy, gx] = [0, 0]
		field[sy][sx] = 0
		queue = [[sy, sx]]
		moves = 0
		while True:
			if len(queue) == 0:
				moves = -2
				break
			queue_next = []
			moves += 1
			for (y, x) in queue:
				for (ny, nx) in tests:
					(ty, tx) = (y + ny, x + nx)
					if field[ty][tx] == '.' or field[ty][tx] == 'G':
						field[ty][tx] = moves
						queue_next.append((ty, tx))
			queue = queue_next
			if goal_point in queue:
				break
		for i in range(len(startqueue)):
			[a, b] = startqueue[i]
			if field[a][b] == 'G':
				ans[times] = 'No'
				break
			elif len(startqueue) - 1 == i:
				break
		else:
			continue
		break
for i in range(t):
	print(ans[i])


def solve(n, m, maze):
	for i in range(n):
		for j in range(m):
			if maze[i][j] != 'B':
				continue
			if i > 0:
				if maze[i - 1][j] == 'G':
					return False
				if maze[i - 1][j] == '.':
					maze[i - 1][j] = '#'
			if j > 0:
				if maze[i][j - 1] == 'G':
					return False
				if maze[i][j - 1] == '.':
					maze[i][j - 1] = '#'
			if i < n - 1:
				if maze[i + 1][j] == 'G':
					return False
				if maze[i + 1][j] == '.':
					maze[i + 1][j] = '#'
			if j < m - 1:
				if maze[i][j + 1] == 'G':
					return False
				if maze[i][j + 1] == '.':
					maze[i][j + 1] = '#'
	reachables = set()
	to_visit = {(n - 1, m - 1)} if maze[n - 1][m - 1] != '#' else set()
	while to_visit:
		(i, j) = to_visit.pop()
		reachables.add((i, j))
		if i > 0 and maze[i - 1][j] != '#' and ((i - 1, j) not in reachables):
			to_visit.add((i - 1, j))
		if i < n - 1 and maze[i + 1][j] != '#' and ((i + 1, j) not in reachables):
			to_visit.add((i + 1, j))
		if j > 0 and maze[i][j - 1] != '#' and ((i, j - 1) not in reachables):
			to_visit.add((i, j - 1))
		if j < m - 1 and maze[i][j + 1] != '#' and ((i, j + 1) not in reachables):
			to_visit.add((i, j + 1))
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'B' and (i, j) in reachables:
				return False
			if maze[i][j] == 'G' and (i, j) not in reachables:
				return False
	return True

def main():
	T = int(input())
	for _ in range(T):
		(n, m) = map(int, input().split())
		maze = [list(input().strip()) for _ in range(n)]
		print('Yes' if solve(n, m, maze) else 'No')
main()


import sys, bisect, string, math, time, functools, random, fractions
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
from itertools import permutations, combinations, groupby
rep = range

def Golf():
	(n, *t) = map(int, open(0).read().split())

def I():
	return int(input())

def S_():
	return input()

def IS():
	return input().split()

def LS():
	return [i for i in input().split()]

def LI():
	return [int(i) for i in input().split()]

def LI_():
	return [int(i) - 1 for i in input().split()]

def NI(n):
	return [int(input()) for i in range(n)]

def NI_(n):
	return [int(input()) - 1 for i in range(n)]

def StoLI():
	return [ord(i) - 97 for i in input()]

def ItoS(n):
	return chr(n + 97)

def LtoS(ls):
	return ''.join([chr(i + 97) for i in ls])

def RA():
	return map(int, open(0).read().split())

def GI(V, E, ls=None, Directed=False, index=1):
	org_inp = []
	g = [[] for i in range(V)]
	FromStdin = True if ls == None else False
	for i in range(E):
		if FromStdin:
			inp = LI()
			org_inp.append(inp)
		else:
			inp = ls[i]
		if len(inp) == 2:
			(a, b) = inp
			c = 1
		else:
			(a, b, c) = inp
		if index == 1:
			a -= 1
			b -= 1
		aa = (a, c)
		bb = (b, c)
		g[a].append(bb)
		if not Directed:
			g[b].append(aa)
	return (g, org_inp)

def GGI(h, w, search=None, replacement_of_found='.', mp_def={'#': 1, '.': 0}, boundary=1):
	mp = [boundary] * (w + 2)
	found = {}
	found['G'] = set()
	found['B'] = set()
	for i in range(h):
		s = input()
		for char in search:
			if char in s:
				found[char].add((i + 1) * (w + 2) + s.index(char) + 1)
				mp_def[char] = mp_def[replacement_of_found]
		mp += [boundary] + [mp_def[j] for j in s] + [boundary]
	mp += [boundary] * (w + 2)
	return (h + 2, w + 2, mp, found)

def TI(n):
	return GI(n, n - 1)

def accum(ls):
	rt = [0]
	for i in ls:
		rt += [rt[-1] + i]
	return rt

def bit_combination(n, base=2):
	rt = []
	for tb in range(base ** n):
		s = [tb // base ** bt % base for bt in range(n)]
		rt += [s]
	return rt

def gcd(x, y):
	if y == 0:
		return x
	if x % y == 0:
		return y
	while x % y != 0:
		(x, y) = (y, x % y)
	return y

def show(*inp, end='\n'):
	if show_flg:
		print(*inp, end=end)
YN = ['YES', 'NO']
Yn = ['Yes', 'No']
mo = 10 ** 9 + 7
inf = float('inf')
FourNb = [(-1, 0), (1, 0), (0, 1), (0, -1)]
EightNb = [(-1, 0), (1, 0), (0, 1), (0, -1), (1, 1), (-1, -1), (1, -1), (-1, 1)]
compas = dict(zip('WENS', FourNb))
cursol = dict(zip('LRUD', FourNb))
l_alp = string.ascii_lowercase
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
input = lambda : sys.stdin.readline().rstrip()

class Tree:

	def __init__(self, inp_size=None, ls=None, init=True, index=1):
		self.LCA_init_stat = False
		self.ETtable = []
		if init:
			if ls == None:
				self.stdin(inp_size, index=index)
			else:
				self.size = len(ls) + 1
				(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def stdin(self, inp_size=None, index=1):
		if inp_size == None:
			self.size = int(input())
		else:
			self.size = inp_size
		(self.edges, _) = GI(self.size, self.size - 1, index=index)
		return

	def listin(self, ls, index=0):
		self.size = len(ls) + 1
		(self.edges, _) = GI(self.size, self.size - 1, ls, index=index)
		return

	def dfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.size
		v[x] = root_v
		while q:
			c = q.pop()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def bfs(self, x, func=lambda pr, prv, nx, dist: prv + dist, root_v=0):
		q = deque([x])
		v = [None] * self.size
		v[x] = root_v
		while q:
			c = q.popleft()
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = func(c, v[c], nb, d)
		return v

	def parent(self, x):
		return self.dfs(0, func=lambda pr, prv, nx, dist: pr, root_v=-1)

	def topological_sort(self, x):
		tps = []
		q = deque([x])
		v = [None] * self.size
		v[x] = 0
		while q:
			c = q.popleft()
			tps.append(c)
			for (nb, d) in self.edges[c]:
				if v[nb] == None:
					q.append(nb)
					v[nb] = 0
		return tps

	def EulerTour(self, x):
		q = deque()
		q.append(x)
		self.depth = [None] * self.size
		self.depth[x] = 0
		self.ETtable = []
		self.ETdepth = []
		self.ETin = [-1] * self.size
		self.ETout = [-1] * self.size
		cnt = 0
		while q:
			c = q.pop()
			if c < 0:
				ce = ~c
			else:
				ce = c
				for (nb, d) in self.edges[ce]:
					if self.depth[nb] == None:
						q.append(~ce)
						q.append(nb)
						self.depth[nb] = self.depth[ce] + 1
			self.ETtable.append(ce)
			self.ETdepth.append(self.depth[ce])
			if self.ETin[ce] == -1:
				self.ETin[ce] = cnt
			else:
				self.ETout[ce] = cnt
			cnt += 1
		return

	def LCA_init(self, root):
		self.EulerTour(root)
		self.st = SparseTable(self.ETdepth, init_func=min, init_idl=inf)
		self.LCA_init_stat = True
		return

	def LCA(self, root, x, y):
		if self.LCA_init_stat == False:
			self.LCA_init(root)
		(xin, xout) = (self.ETin[x], self.ETout[x])
		(yin, yout) = (self.ETin[y], self.ETout[y])
		a = min(xin, yin)
		b = max(xout, yout, xin, yin)
		id_of_min_dep_in_et = self.st.query_id(a, b + 1)
		return self.ETtable[id_of_min_dep_in_et]

	def __str__(self):
		return str(self.edges)

	def show(self):
		if all([all([d == 1 for (nd, d) in edge]) for edge in self.edges]):
			print([[nd for (nd, d) in edge] for edge in self.edges])
		else:
			print(self)

class SparseTable:

	def __init__(self, ls, init_func=min, init_idl=float('inf')):
		self.func = init_func
		self.idl = init_idl
		self.size = len(ls)
		self.N0 = self.size.bit_length()
		self.table = [ls[:]]
		self.index = [list(range(self.size))]
		self.lg = [0] * (self.size + 1)
		for i in range(2, self.size + 1):
			self.lg[i] = self.lg[i >> 1] + 1
		for i in range(self.N0):
			tmp = [self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) for j in range(self.size)]
			tmp_id = [self.index[i][j] if self.table[i][j] == self.func(self.table[i][j], self.table[i][min(j + (1 << i), self.size - 1)]) else self.index[i][min(j + (1 << i), self.size - 1)] for j in range(self.size)]
			self.table += [tmp]
			self.index += [tmp_id]

	def query(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		return self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))])

	def query_id(self, l, r):
		if r > self.size:
			r = self.size
		N = self.lg[r - l]
		(a, b) = (self.index[N][l], self.index[N][max(0, r - (1 << N))])
		if self.table[0][a] == self.func(self.table[N][l], self.table[N][max(0, r - (1 << N))]):
			b = a
		return b

	def right_bound(self, pos, x):
		k = (self.size - pos).bit_length()
		for j in range(k)[::-1]:
			nx = pos + (1 << j)
			if nx < n and self.query(pos, nx + 1) <= x:
				pos += 1 << j
		return pos

	def left_bound(self, pos, x):
		k = pos.bit_length()
		for j in range(k)[::-1]:
			nx = pos - (1 << j)
			if 0 <= nx and self.query(nx, pos + 1) <= x:
				pos -= 1 << j
		return pos

	def __str__(self):
		return str(self.table[0])

	def print(self):
		for i in self.table:
			print(*i)
show_flg = False
show_flg = True
ans = 0

def bfs(h, w):
	ok = 0
	if g[h - 1][w - 1] == 1:
		return 0
	q = deque([(h - 1, w - 1)])
	v = [[None] * w for i in range(h)]
	v[h - 1][w - 1] = 0
	while q:
		(i, j) = q.popleft()
		for (di, dj) in FourNb:
			if 0 <= i + di < h and 0 <= j + dj < w and (v[i + di][j + dj] == None):
				v[i + di][j + dj] = 0
				if g[i + di][j + dj] != 1:
					q.append((i + di, j + dj))
					if g[i + di][j + dj] == 9:
						ok += 1
	return ok
for _ in range(I()):
	(h, w) = LI()
	good = 0
	g = [[0] * w for i in range(h)]
	for i in range(h):
		s = input()
		for j in range(w):
			if s[j] == 'G':
				if g[i][j] == 0:
					g[i][j] = 9
				good += 1
			elif s[j] == '#':
				g[i][j] = 1
			elif s[j] == '.':
				0
			elif s[j] == 'B':
				for (di, dj) in FourNb:
					if 0 <= i + di < h and 0 <= j + dj < w:
						g[i + di][j + dj] = 1
	ok = bfs(h, w)
	if ok == good:
		ans = 0
	else:
		ans = 1
	print(Yn[ans])


from sys import stdin, stdout

def solve_the_maze(maze, n, m):
	dir = [[1, 0], [-1, 0], [0, 1], [0, -1]]
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'B':
				for d in dir:
					di = i + d[0]
					dj = j + d[1]
					if 0 <= di < n and 0 <= dj < m:
						if maze[di][dj] == 'G':
							return 'NO'
						elif maze[di][dj] == '.':
							maze[di][dj] = '#'
	ufa = [0 for i in range(m * n)]
	for i in range(len(ufa)):
		ufa[i] = i
	for i in range(n - 1, -1, -1):
		for j in range(m - 1, -1, -1):
			if maze[i][j] == '#':
				continue
			if j + 1 < m and maze[i][j + 1] != '#':
				union(ufa, m * i + j, m * i + j + 1)
			if i + 1 < n and maze[i + 1][j] != '#':
				union(ufa, m * i + j, m * (i + 1) + j)
	root = ufind(ufa, n * m - 1)
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'G':
				grp = ufind(ufa, i * m + j)
				if grp != root:
					return 'NO'
	return 'YES'

def union(ufa, a, b):
	ar = ufind(ufa, a)
	br = ufind(ufa, b)
	ufa[br] = ar

def ufind(ufa, a):
	if ufa[a] == a:
		return a
	ufa[a] = ufind(ufa, ufa[a])
	return ufa[a]
t = int(stdin.readline())
for i in range(t):
	(n, m) = list(map(int, stdin.readline().split()))
	maze = []
	for i in range(n):
		maze.append(list(stdin.readline().strip()))
	if i == 62:
		print(maze)
	stdout.write(solve_the_maze(maze, n, m) + '\n')


import sys
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
(t,) = I()
for _ in range(t):
	(n, m) = I()
	l = []
	cg = cb = 0
	for i in range(n):
		s = list(input().strip())
		l.append(s)
		cg += s.count('G')
		cb += s.count('B')
	for i in range(n):
		for j in range(m):
			if l[i][j] == 'B':
				xt = 0
				x = i
				y = j
				if x + 1 < n and l[x + 1][y] not in ['G', 'B']:
					l[x + 1][y] = '#'
				if y + 1 < m and l[x][y + 1] not in ['G', 'B']:
					l[x][y + 1] = '#'
				if x - 1 >= 0 and l[x - 1][y] not in ['G', 'B']:
					l[x - 1][y] = '#'
				if y - 1 >= 0 and l[x][y - 1] not in ['G', 'B']:
					l[x][y - 1] = '#'
	if cg == 0:
		print('Yes')
	elif (n >= 2 and m >= 2) and (l[n - 2][m - 1] == 'B' or l[n - 1][m - 2] == 'B'):
		print('No')
	else:
		tt = [[0] * m for i in range(n)]

		def dfs(x, y, i, mt):
			mt[x][y] = i
			if x + 1 < n and mt[x + 1][y] == 0 and (l[x + 1][y] not in ['#', 'B']):
				mt[x + 1][y] = i
				dfs(x + 1, y, i, mt)
			if y + 1 < m and mt[x][y + 1] == 0 and (l[x][y + 1] not in ['#', 'B']):
				mt[x][y + 1] = i
				dfs(x, y + 1, i, mt)
			if x - 1 >= 0 and mt[x - 1][y] == 0 and (l[x - 1][y] not in ['#', 'B']):
				mt[x - 1][y] = i
				dfs(x - 1, y, i, mt)
			if y - 1 >= 0 and mt[x][y - 1] == 0 and (l[x][y - 1] not in ['#', 'B']):
				mt[x][y - 1] = i
				dfs(x, y - 1, i, mt)
		dfs(n - 1, m - 1, 2, tt)
		ct = 0
		for i in range(n):
			for j in range(m):
				if l[i][j] == 'G':
					xt = 0
					x = i
					y = j
					if x + 1 < n and l[x + 1][y] == 'B':
						xt += 1
					if y + 1 < m and l[x][y + 1] == 'B':
						xt += 1
					if x - 1 >= 0 and l[x - 1][y] == 'B':
						xt += 1
					if y - 1 >= 0 and l[x][y - 1] == 'B':
						xt += 1
					if tt[i][j] != 2 or xt != 0:
						ct += 1
						break
			if ct:
				break
		if ct:
			print('No')
		elif cb == 0:
			print('Yes')
		else:
			f = 0
			print('YNeos'[f::2])


def block(l, n, m):
	for i in range(n):
		for j in range(m):
			if l[i][j] == 'B':
				nei = [(max(i - 1, 0), j), (min(i + 1, n - 1), j), (i, max(j - 1, 0)), (i, min(j + 1, m - 1))]
				for nnn in nei:
					if l[nnn[0]][nnn[1]] == 'G':
						return False
					elif l[nnn[0]][nnn[1]] == 'B':
						continue
					else:
						l[nnn[0]][nnn[1]] = '#'
	return True

def findpath(l, xxx, n, m, i, j):
	if l[i][j] == 'G':
		l[i][j] = '.'
	xxx[i][j] = 1
	if i == n - 1 and j == m - 1:
		return True
	nei = [(max(i - 1, 0), j), (min(i + 1, n - 1), j), (i, max(j - 1, 0)), (i, min(j + 1, m - 1))]
	end = False
	for nnn in nei:
		if l[nnn[0]][nnn[1]] in ['.', 'G'] and xxx[nnn[0]][nnn[1]] == 0:
			end = findpath(l, xxx, n, m, nnn[0], nnn[1])
			if end:
				break
	return end

def solve(l, n, m):
	for i in range(n):
		for j in range(m):
			if l[i][j] == 'G':
				xxx = [[0 for _ in range(m)] for _ in range(n)]
				xxx[i][j] = 1
				if not findpath(l, xxx, n, m, i, j):
					return False
	return True

def fill(l, xx, n, m, i, j):
	nei = [(max(i - 1, 0), j), (min(i + 1, n - 1), j), (i, max(j - 1, 0)), (i, min(j + 1, m - 1))]
	for nnn in nei:
		if l[nnn[0]][nnn[1]] in ['.', 'G'] and xx[nnn[0]][nnn[1]] == 0:
			xx[nnn[0]][nnn[1]] = 1
			l[nnn[0]][nnn[1]] = '.'
			fill(l, xx, n, m, nnn[0], nnn[1])
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for _ in range(n):
		l.append([i for i in input()])
	if not block(l, n, m):
		print('No')
		continue
	if l[n - 1][m - 1] == '#':
		end = False
		for i in range(n):
			for j in range(m):
				if l[i][j] == 'G':
					end = True
					break
			if end:
				break
		print('No' if end else 'Yes')
		continue
	xx = [[0 for _ in range(m)] for _ in range(n)]
	fill(l, xx, n, m, n - 1, m - 1)
	end = False
	for i in range(n):
		for j in range(m):
			if l[i][j] == 'G':
				end = True
				break
		if end:
			break
	print('No' if end else 'Yes')


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')


import sys
sys.setrecursionlimit(100000)
DIR = [(-1, 0), (1, 0), (0, -1), (0, 1)]

def dfs(i, j):
	if i > n or i == 0 or j > m or (j == 0):
		return
	used[i][j] = 1
	for (di, dj) in DIR:
		if not used[i + di][j + dj] and a[i + di][j + dj] != '#':
			dfs(i + di, j + dj)
for t in range(int(input())):
	(n, m) = list(map(int, input().split()))
	a = [['#'] * (m + 2)] + [list('#' + input() + '#') for i in range(n)] + [['#'] * (m + 2)]
	used = [[0] * (m + 2) for i in range(n + 2)]
	ok = True
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if a[i][j] == 'B':
				for (di, dj) in DIR:
					if a[i + di][j + dj] == 'G':
						ok = False
					elif a[i + di][j + dj] != 'B':
						a[i + di][j + dj] = '#'
	if a[n][m] != '#':
		dfs(n, m)
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if a[i][j] == 'G' and (not used[i][j]):
				ok = False
	print('Yes' if ok else 'No')


import sys
import collections as cc
import bisect as bi
sys.setrecursionlimit(10 ** 5)
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n, m) = I()
	ar = []
	g = 0
	b = 0
	for i in range(n):
		te = list(input())
		ar.append(te)
		g += te.count('G')
		b += te.count('B')
	tf = 1
	for i in range(n):
		for j in range(m):
			if ar[i][j] == 'B':
				x = i
				y = j
				if x + 1 < n:
					if ar[x + 1][y] == '.':
						ar[x + 1][y] = '#'
					elif ar[x + 1][y] == 'G':
						tf = 0
				if x - 1 >= 0:
					if ar[x - 1][y] == '.':
						ar[x - 1][y] = '#'
					elif ar[x - 1][y] == 'G':
						tf = 0
				if y + 1 < m:
					if ar[x][y + 1] == '.':
						ar[x][y + 1] = '#'
					elif ar[x][y + 1] == 'G':
						tf = 0
				if y - 1 >= 0:
					if ar[x][y - 1] == '.':
						ar[x][y - 1] = '#'
					elif ar[x][y - 1] == 'G':
						tf = 0
	if g == 0:
		print('YES')
	elif not tf:
		print('NO')
	elif tf:
		temp = [[0] * m for i in range(n)]

		def dfs(x, y, temp):
			temp[x][y] = 'W'
			if x + 1 < n and temp[x + 1][y] == 0 and (ar[x + 1][y] not in ['#', 'B']):
				dfs(x + 1, y, temp)
			if y + 1 < m and temp[x][y + 1] == 0 and (ar[x][y + 1] not in ['#', 'B']):
				dfs(x, y + 1, temp)
			if x - 1 >= 0 and temp[x - 1][y] == 0 and (ar[x - 1][y] not in ['#', 'B']):
				dfs(x - 1, y, temp)
			if y - 1 >= 0 and temp[x][y - 1] == 0 and (ar[x][y - 1] not in ['#', 'B']):
				dfs(x, y - 1, temp)
		if ar[n - 1][m - 1] == '#':
			print('NO')
			continue
		dfs(n - 1, m - 1, temp)
		ttt = 1
		for i in range(n):
			ttt = 1
			for j in range(m):
				ttt = 1
				if ar[i][j] == 'G':
					if temp[i][j] == 'W':
						ttt = 1
					else:
						ttt = 0
						break
			if not ttt:
				break
		if ttt:
			print('YES')
		else:
			print('NO')


from collections import deque

def bfs():
	global n, m, s, d, check
	while len(d):
		l = len(d)
		for i in range(l):
			p = d.popleft()
			for j in [[p[0], p[1] + 1], [p[0], p[1] - 1], [p[0] + 1, p[1]], [p[0] - 1, p[1]]]:
				if not check[j[0]][j[1]]:
					check[j[0]][j[1]] = True
					d.append(j)
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = [['#' for i in range(m + 2)]] + [list('#' + input() + '#') for i in range(n)] + [['#' for i in range(m + 2)]]
	f = False
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if s[i][j] == 'B':
				for k in [[i, j + 1], [i, j - 1], [i - 1, j], [i + 1, j]]:
					if s[k[0]][k[1]] == 'G':
						f = True
					elif s[k[0]][k[1]] == '.':
						s[k[0]][k[1]] = '#'
	if f:
		print('No')
		continue
	if s[n][m] == 'B' or s[n][m] == '#':
		for i in range(1, n + 1):
			for j in range(1, m + 1):
				if s[i][j] == 'G':
					f = True
		if not f:
			print('Yes')
		else:
			print('No')
		continue
	d = deque()
	d.append([n, m])
	check = [[s[i][j] == 'B' or s[i][j] == '#' for j in range(m + 2)] for i in range(n + 2)]
	check[n][m] = True
	bfs()
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if s[i][j] == 'G' and check[i][j] == False:
				f = True
	if f:
		print('No')
		continue
	print('Yes')


import sys
readline = sys.stdin.readline
from sys import setrecursionlimit
setrecursionlimit(10 ** 5)
dx = [0, 0, -1, 1]
dy = [1, -1, 0, 0]
DIR = [(-1, 0), (1, 0), (0, -1), (0, 1)]

def is_valid(i, j, n, m):
	if i >= 0 and j >= 0 and (i < n) and (j < m):
		return True
	else:
		return False

def dfs(x, y):
	visited[x][y] = 1
	for (di, dj) in DIR:
		xx = x + di
		yy = y + dj
		if is_valid(xx, yy, n, m) and (not visited[xx][yy]) and (grid[xx][yy] != '#'):
			dfs(xx, yy)
for t in range(int(readline().rstrip())):
	(n, m) = map(int, readline().split())
	visited = [[0 for _ in range(m)] for _ in range(n)]
	grid = [list(readline().rstrip()) for _ in range(n)]
	ok = True
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 'B':
				for (di, dj) in DIR:
					xx = i + di
					yy = j + dj
					if is_valid(xx, yy, n, m):
						if grid[xx][yy] == 'G':
							ok = False
						if grid[xx][yy] == '.':
							grid[xx][yy] = '#'
	if grid[n - 1][m - 1] != '#':
		dfs(n - 1, m - 1)
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 'G' and (not visited[i][j]):
				ok = False
	print('yes' if ok else 'no')


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]

def valid(a, b):
	return 0 <= a < n and 0 <= b < m

def bfs(a, b):
	q = deque()
	q.append((a, b))
	while q:
		(t1, t2) = q.popleft()
		for k in range(4):
			(a, b) = (t1 + x[k], t2 + y[k])
			if valid(a, b) and (not vis[a, b]) and (mat[a][b] in ['B', 'G', '.']):
				vis[a, b] = True
				q.append((a, b))
for _ in range(int(data())):
	(n, m) = sp()
	mat = []
	g = []
	for i in range(n):
		mat.append(list(data()))
		if 'G' in mat[i]:
			for j in range(m):
				if mat[i][j] == 'G':
					g.append((i, j))
	(x, y) = ([-1, 1, 0, 0], [0, 0, -1, 1])
	r = True
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 'B':
				for k in range(4):
					if valid(i + x[k], j + y[k]) and mat[i + x[k]][j + y[k]] == '.':
						mat[i + x[k]][j + y[k]] = '#'
					if valid(i + x[k], j + y[k]) and mat[i + x[k]][j + y[k]] == 'G':
						r = False
						break
			if not r:
				break
		if not r:
			break
	if not r or (mat[n - 1][m - 1] == '#' and g):
		out('NO')
		continue
	if not g:
		out('Yes')
		continue
	vis = dd(bool)
	bfs(g[0][0], g[0][1])
	for i in g:
		if not vis[tuple(i)]:
			r = False
			break
	if not vis[n - 1, m - 1]:
		r = False
	out(('No', 'Yes')[r])


from collections import deque
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	maze = [['#'] * (m + 2)] + [['#'] + list(input().strip()) + ['#'] for _ in range(n)] + [['#'] * (m + 2)]

	def neighbours(r, c):
		yield (r, c - 1)
		yield (r - 1, c)
		yield (r + 1, c)
		yield (r, c + 1)
	good_guys = set()
	possible = True
	for r in range(1, n + 1):
		for c in range(1, m + 1):
			if maze[r][c] == 'B':
				for (nr, nc) in neighbours(r, c):
					if maze[nr][nc] == 'G':
						possible = False
						break
					elif maze[nr][nc] == '.':
						maze[nr][nc] = '#'
			elif maze[r][c] == 'G':
				good_guys.add((r, c))
	if len(good_guys) == 0:
		print('Yes')
		continue
	if maze[n][m] == '#':
		possible = False
	if possible:
		visited = set()
		visited.add((n, m))
		q = deque()
		q.append((n, m))
		while q:
			(pr, pc) = q.popleft()
			for (nr, nc) in filter(lambda n: n not in visited, neighbours(pr, pc)):
				if maze[nr][nc] in ['.', 'G']:
					visited.add((nr, nc))
					q.append((nr, nc))
		for good_guy in good_guys:
			if good_guy not in visited:
				print('No')
				break
		else:
			print('Yes')
	else:
		print('No')


q = int(input())
for _ in range(q):
	(r, c) = map(int, input().split())

	def nbr(x, y):
		out = []
		if x < r - 1:
			out.append([x + 1, y])
		if x > 0:
			out.append([x - 1, y])
		if y > 0:
			out.append([x, y - 1])
		if y < c - 1:
			out.append([x, y + 1])
		return out
	mat = [list(input()) for i in range(r)]
	for x in range(r):
		for y in range(c):
			if mat[x][y] == 'B':
				for p in nbr(x, y):
					if mat[p[0]][p[1]] != 'G' and mat[p[0]][p[1]] != 'B':
						mat[p[0]][p[1]] = '#'
	zaj = {}
	for x in range(r):
		for y in range(c):
			zaj[x, y] = 0
	if mat[r - 1][c - 1] == '#':
		su = 0
		for i in range(r):
			su += mat[i].count('G')
		if su == 0:
			print('Yes')
		else:
			print('No')
	else:
		zaj[r - 1, c - 1] = 1

		def dupa(v):
			q = [v]
			while q:
				w = q.pop(0)
				for u in nbr(w[0], w[1]):
					if mat[u[0]][u[1]] != '#':
						if zaj[tuple(u)] == 0:
							q.append(tuple(u))
							zaj[tuple(u)] = 1
		dupa((r - 1, c - 1))
		dasie = True
		for x in range(r):
			for y in range(c):
				if mat[x][y] == 'B' and zaj[x, y] == 1:
					dasie = False
				if mat[x][y] == 'G' and zaj[x, y] == 0:
					dasie = False
		if dasie:
			print('Yes')
		else:
			print('No')


import sys
from math import sqrt, gcd, ceil, log
from collections import defaultdict, Counter, deque
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))
main()


from sys import stdin
input = stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	text = []
	for i in range(n):
		temp = list(input())
		text.append(temp)
	flag = 0
	for i in range(n):
		for j in range(m):
			if text[i][j] != 'B':
				continue
			if i > 0:
				if text[i - 1][j] == '.':
					text[i - 1][j] = '#'
			if i < n - 1:
				if text[i + 1][j] == '.':
					text[i + 1][j] = '#'
			if j > 0:
				if text[i][j - 1] == '.':
					text[i][j - 1] = '#'
			if j < m - 1:
				if text[i][j + 1] == '.':
					text[i][j + 1] = '#'
	arr = []
	for i in range(n):
		arr.append([0] * m)
	queue = []
	if text[n - 1][m - 1] == '.':
		queue.append((n - 1, m - 1))
	while queue:
		curr = queue.pop()
		(i, j) = curr
		arr[i][j] = 1
		if i > 0:
			if text[i - 1][j] != '#' and arr[i - 1][j] == 0:
				queue.append((i - 1, j))
		if i < n - 1:
			if text[i + 1][j] != '#' and arr[i + 1][j] == 0:
				queue.append((i + 1, j))
		if j > 0:
			if text[i][j - 1] != '#' and arr[i][j - 1] == 0:
				queue.append((i, j - 1))
		if j < m - 1:
			if text[i][j + 1] != '#' and arr[i][j + 1] == 0:
				queue.append((i, j + 1))
	for i in range(n):
		for j in range(m):
			if text[i][j] == 'B':
				if arr[i][j] == 1:
					flag = 1
					break
			if text[i][j] == 'G':
				if arr[i][j] == 0:
					flag = 1
					break
	if flag:
		print('No')
	else:
		print('Yes')


T = int(input())
for t in range(0, T):
	l = input().split()
	n = int(l[0])
	m = int(l[1])
	maze = []
	for i in range(0, n):
		maze.append(list(input().strip()))
	good = True
	total = 0
	coord = [(-1, 0), (1, 0), (0, -1), (0, 1)]
	for i in range(0, n):
		if not good:
			break
		for j in range(0, m):
			if maze[i][j] == 'B':
				for k in range(0, 4):
					if 0 <= i + coord[k][0] < n and 0 <= j + coord[k][1] < m:
						if maze[i + coord[k][0]][j + coord[k][1]] == '.':
							maze[i + coord[k][0]][j + coord[k][1]] = '#'
						elif maze[i + coord[k][0]][j + coord[k][1]] == 'G':
							good = False
							break
			elif maze[i][j] == 'G':
				total += 1
	if not good:
		print('No')
		continue
	count = 0
	s = []
	if maze[n - 1][m - 1] != '#':
		s.append((n - 1, m - 1))
	found = set([])
	while not s == []:
		t = s.pop()
		if t in found:
			continue
		if maze[t[0]][t[1]] == 'G':
			count += 1
		found.add(t)
		for p in coord:
			nc = (t[0] + p[0], t[1] + p[1])
			if 0 <= nc[0] < n and 0 <= nc[1] < m and (nc not in found):
				if not maze[nc[0]][nc[1]] == '#':
					s.append(nc)
	if count == total:
		print('Yes')
	else:
		print('No')


from collections import defaultdict
t = int(input())
for test in range(t):
	(n, m) = list(map(int, input().split()))
	arr = []
	for i in range(n):
		arr.append(list(input()))
	err = False
	hasG = False
	hasB = True
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'B':
				hasB = True
				if i - 1 >= 0 and arr[i - 1][j] == 'G' or (i + 1 < n and arr[i + 1][j] == 'G') or (j - 1 >= 0 and arr[i][j - 1] == 'G') or (j + 1 < m and arr[i][j + 1] == 'G'):
					err = True
			elif arr[i][j] == 'G':
				hasG = True
			elif arr[i][j] == '.':
				if i - 1 >= 0 and arr[i - 1][j] == 'B' or (i + 1 < n and arr[i + 1][j] == 'B') or (j - 1 >= 0 and arr[i][j - 1] == 'B') or (j + 1 < m and arr[i][j + 1] == 'B'):
					arr[i][j] = '#'
	if err or (hasG and (n - 2 >= 0 and arr[n - 2][m - 1] == 'B' or (m - 2 >= 0 and arr[n - 1][m - 2] == 'B'))):
		print('No')
	else:
		ans = True
		visited = [[False for i in range(m)] for i in range(n)]
		q = [(n - 1, m - 1)]
		while len(q) > 0:
			(x, y) = q.pop()
			if x - 1 >= 0 and arr[x - 1][y] != '#' and (not visited[x - 1][y]):
				visited[x - 1][y] = True
				q.append((x - 1, y))
			if y - 1 >= 0 and arr[x][y - 1] != '#' and (not visited[x][y - 1]):
				visited[x][y - 1] = True
				q.append((x, y - 1))
			if x + 1 < n and arr[x + 1][y] != '#' and (not visited[x + 1][y]):
				visited[x + 1][y] = True
				q.append((x + 1, y))
			if y + 1 < m and arr[x][y + 1] != '#' and (not visited[x][y + 1]):
				visited[x][y + 1] = True
				q.append((x, y + 1))
		for i in range(n):
			for j in range(m):
				if arr[i][j] == 'G' and (not visited[i][j]):
					ans = False
					break
			if not ans:
				break
		if ans:
			print('Yes')
		else:
			print('No')


t = int(input())
while t > 0:
	t -= 1
	(n, m) = map(int, input().strip().split(' '))
	arr = []
	for i in range(n):
		arr.append(list(input().strip()))
	row = [0, 0, 1, -1]
	col = [1, -1, 0, 0]
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'B':
				for k in range(4):
					a = i + row[k]
					b = j + col[k]
					if a >= 0 and a < n and (b >= 0) and (b < m):
						if arr[a][b] == '.':
							arr[a][b] = '#'
	queue = []
	visited = [[False for i in range(m + 1)] for j in range(n + 1)]
	if arr[n - 1][m - 1] == '.':
		queue.append([n - 1, m - 1])
		visited[n - 1][m - 1] = True
	while queue:
		curr = queue.pop(0)
		for i in range(4):
			a = curr[0] + row[i]
			b = curr[1] + col[i]
			if a >= 0 and a < n and (b >= 0) and (b < m):
				if arr[a][b] != '#' and (not visited[a][b]):
					queue.append([a, b])
					visited[a][b] = True
	ans = True
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'B' and visited[i][j]:
				ans = False
			elif arr[i][j] == 'G' and (not visited[i][j]):
				ans = False
	if ans:
		print('Yes')
	else:
		print('No')


n = int(input())
for i in range(n):
	(r, s) = [int(k) for k in input().split(' ')]
	maze = [input() for j in range(r)]
	good = set()
	bad = set()
	walls = set()
	for (num, line) in enumerate(maze):
		for (mun, c) in enumerate(line):
			component = maze[num][mun]
			if component == 'G':
				good.add((num, mun))
			elif component == 'B':
				bad.add((num, mun))
			elif component == '#':
				walls.add((num, mun))
	check = True
	if len(good) == 0:
		print('Yes')
		check = False
	for bg in bad:
		for (x, y) in [(0, -1), (0, +1), (-1, 0), (+1, 0)]:
			rx = bg[0] + x
			sy = bg[1] + y
			if not min(rx, sy) < 0 and rx < r and (sy < s):
				if maze[rx][sy] == 'G':
					print('No')
					check = False
					break
				elif maze[rx][sy] == '.':
					walls.add((rx, sy))
		if not check:
			break
	if not check:
		continue
	if (r - 1, s - 1) in walls or maze[r - 1][s - 1] == 'B':
		print('No')
	else:
		found_good = set()
		visited = set()
		visited.add((r - 1, s - 1))
		q = [(r - 1, s - 2), (r - 2, s - 1)]
		while len(found_good) != len(good) and len(q) != 0:
			coor = q.pop()
			if maze[coor[0]][coor[1]] == 'G':
				found_good.add(coor)
				for (x, y) in [(0, -1), (0, +1), (-1, 0), (+1, 0)]:
					rx = coor[0] + x
					sy = coor[1] + y
					if not min(rx, sy) < 0 and rx < r and (sy < s):
						if not (rx, sy) in visited:
							q.append((rx, sy))
							visited.add((rx, sy))
			if not coor in walls and (not coor in bad):
				for (x, y) in [(0, -1), (0, +1), (-1, 0), (+1, 0)]:
					rx = coor[0] + x
					sy = coor[1] + y
					if not min(rx, sy) < 0 and rx < r and (sy < s):
						if not (rx, sy) in visited:
							q.append((rx, sy))
							visited.add((rx, sy))
		if len(found_good) == len(good):
			print('Yes')
		else:
			print('No')


from math import *

def r1(t):
	return t(input())

def r2(t):
	return [t(i) for i in input().split()]

def r3(t):
	return [t(i) for i in input()]
g = []

def dfs(i, j, n, m):
	if g[i][j] == '#':
		return 0
	ans = 0
	if g[i][j] == 'G':
		ans += 1
	if g[i][j] == 'B':
		return -100000
	g[i][j] = '#'
	if i > 0:
		ans += dfs(i - 1, j, n, m)
	if i < n - 1:
		ans += dfs(i + 1, j, n, m)
	if j > 0:
		ans += dfs(i, j - 1, n, m)
	if j < m - 1:
		ans += dfs(i, j + 1, n, m)
	return ans
for _ in range(r1(int)):
	(n, m) = r2(int)
	g = []
	used = []
	for i in range(n):
		g.append(r3(str))
	cnt = 0
	for i in range(n):
		for j in range(m):
			if g[i][j] == 'B':
				if i > 0 and g[i - 1][j] == '.':
					g[i - 1][j] = '#'
				if i < n - 1 and g[i + 1][j] == '.':
					g[i + 1][j] = '#'
				if j > 0 and g[i][j - 1] == '.':
					g[i][j - 1] = '#'
				if j < m - 1 and g[i][j + 1] == '.':
					g[i][j + 1] = '#'
			elif g[i][j] == 'G':
				cnt += 1
	if dfs(n - 1, m - 1, n, m) == cnt:
		print('Yes')
	else:
		print('No')


def ss(n, m, l):
	a = []
	b = []
	for i in range(n):
		for j in range(m):
			if l[i][j] == 'B':
				a.append([i, j])
			elif l[i][j] == 'G':
				b.append([i, j])
	if len(b) == 0:
		return 'Yes'
	t = [[0, 1], [1, 0], [-1, 0], [0, -1]]
	for (x, y) in a:
		for (dx, dy) in t:
			nx = x + dx
			ny = y + dy
			if nx < n and ny < m and (nx >= 0) and (ny >= 0):
				if l[nx][ny] == 'G':
					return 'No'
				if l[nx][ny] == '.':
					l[nx][ny] = '#'
	if l[n - 1][m - 1] == '#':
		if len(b) == 0:
			return 'Yes'
		return 'No'
	q = [[n - 1, m - 1]]
	while q:
		q1 = []
		for (x, y) in q:
			for (dx, dy) in t:
				nx = x + dx
				ny = y + dy
				if nx < n and ny < m and (nx >= 0) and (ny >= 0) and (l[nx][ny] != '#'):
					l[nx][ny] = '#'
					q1.append([nx, ny])
		q = q1
	for i in range(n):
		for j in range(m):
			if l[i][j] == 'G':
				return 'No'
	return 'Yes'
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(list(str(input())))
	print(ss(n, m, l))


import os, sys
from io import IOBase, BytesIO
py2 = round(0.5)
if py2:
	from future_builtins import ascii, filter, hex, map, oct, zip
	range = xrange
BUFSIZE = 8192

class FastIO(BytesIO):
	newlines = 0

	def __init__(self, file):
		self._file = file
		self._fd = file.fileno()
		self.writable = 'x' in file.mode or 'w' in file.mode
		self.write = super(FastIO, self).write if self.writable else None

	def _fill(self):
		s = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
		self.seek((self.tell(), self.seek(0, 2), super(FastIO, self).write(s))[0])
		return s

	def read(self):
		while self._fill():
			pass
		return super(FastIO, self).read()

	def readline(self):
		while self.newlines == 0:
			s = self._fill()
			self.newlines = s.count(b'\n') + (not s)
		self.newlines -= 1
		return super(FastIO, self).readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.getvalue())
			(self.truncate(0), self.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		if py2:
			self.write = self.buffer.write
			self.read = self.buffer.read
			self.readline = self.buffer.readline
		else:
			self.write = lambda s: self.buffer.write(s.encode('ascii'))
			self.read = lambda : self.buffer.read().decode('ascii')
			self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import sys

class ostream:

	def __lshift__(self, a):
		sys.stdout.write(str(a))
		return self
cout = ostream()
endl = '\n'
t = int(input())
from collections import defaultdict

def vb():
	for i in range(n):
		for j in range(m):
			if ma[i][j] == 'B':
				if i > 0 and ma[i - 1][j] == 'G':
					return False
				if i > 0 and ma[i - 1][j] == '.':
					ma[i - 1][j] = '#'
				if i < n - 1 and ma[i + 1][j] == 'G':
					return False
				if i < n - 1 and ma[i + 1][j] == '.':
					ma[i + 1][j] = '#'
				if j > 0 and ma[i][j - 1] == 'G':
					return False
				if j > 0 and ma[i][j - 1] == '.':
					ma[i][j - 1] = '#'
				if j < m - 1 and ma[i][j + 1] == 'G':
					return False
				if j < m - 1 and ma[i][j + 1] == '.':
					ma[i][j + 1] = '#'
	if ma[n - 1][m - 1] == '#' and gg != 0:
		return False
	return True
for _ in range(t):
	(n, m) = map(int, input().split())
	ma = []
	gg = 0
	for i in range(n):
		c = list(str(input()))
		gg += c.count('G')
		ma.append(c)
	if not vb():
		print('NO')
		continue
	g = 0
	v = defaultdict(lambda : False)
	s = [(n - 1, m - 1)]
	while s:
		(x, y) = s.pop()
		if v[x, y]:
			continue
		v[x, y] = True
		if ma[x][y] == 'G':
			g += 1
		if x + 1 < n and ma[x + 1][y] != '#':
			s.append((x + 1, y))
		if x - 1 > -1 and ma[x - 1][y] != '#':
			s.append((x - 1, y))
		if y + 1 < m and ma[x][y + 1] != '#':
			s.append((x, y + 1))
		if y - 1 > -1 and ma[x][y - 1] != '#':
			s.append((x, y - 1))
	if g == gg:
		print('YES')
	else:
		print('NO')


import sys
input = sys.stdin.readline

def dfs(i, j, n, m):
	if arr[i][j] == '#':
		return 0
	ans = 0
	if arr[i][j] == 'G':
		ans += 1
	if arr[i][j] == 'B':
		return -100000
	arr[i][j] = '#'
	if i > 0:
		ans += dfs(i - 1, j, n, m)
	if i < n - 1:
		ans += dfs(i + 1, j, n, m)
	if j > 0:
		ans += dfs(i, j - 1, n, m)
	if j < m - 1:
		ans += dfs(i, j + 1, n, m)
	return ans
for t in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		arr.append(list(input()))
	good = 0
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'G':
				good += 1
			if arr[i][j] == 'B':
				if i > 0 and arr[i - 1][j] == '.':
					arr[i - 1][j] = '#'
				if j < m - 1 and arr[i][j + 1] == '.':
					arr[i][j + 1] = '#'
				if i < n - 1 and arr[i + 1][j] == '.':
					arr[i + 1][j] = '#'
				if j > 0 and arr[i][j - 1] == '.':
					arr[i][j - 1] = '#'
	if dfs(n - 1, m - 1, n, m) == good:
		print('YES')
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import heapq
import collections

def main():
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, input().split())
		table = []
		BList = []
		GList = []
		for i in range(n):
			temp = input().strip()
			table.append([])
			for j in range(m):
				table[-1].append(temp[j])
				if table[-1][-1] == 'B':
					BList.append((i, j))
				if table[-1][-1] == 'G':
					GList.append((i, j))
		if not GList:
			print('Yes')
			continue
		flag = True
		if BList:
			BList = collections.deque(BList)
			while BList:
				BList.append(None)
				while True:
					temp = BList.popleft()
					if temp == None:
						break
					(x, y) = (temp[0], temp[1])
					if table[x][y] == 'B':
						table[x][y] = '.'
						if x > 0:
							BList.append((x - 1, y))
						if x < n - 1:
							BList.append((x + 1, y))
						if y > 0:
							BList.append((x, y - 1))
						if y < m - 1:
							BList.append((x, y + 1))
					if table[x][y] == '.':
						table[x][y] = '#'
					if table[x][y] == 'G':
						flag = False
						break
				if not flag:
					break
		if not flag or table[-1][-1] == '#':
			print('No')
			continue
		cnt = 0
		stack = [(n - 1, m - 1)]
		while stack:
			(x, y) = stack.pop()
			if table[x][y] in ['*', '#']:
				continue
			if table[x][y] in ['.', 'G']:
				if table[x][y] == 'G':
					cnt += 1
				if x > 0:
					stack.append((x - 1, y))
				if x < n - 1:
					stack.append((x + 1, y))
				if y > 0:
					stack.append((x, y - 1))
				if y < m - 1:
					stack.append((x, y + 1))
			table[x][y] = '*'
		if cnt == len(GList):
			print('Yes')
		else:
			print('No')
	return
main()


from collections import deque
T = int(input())
for t in range(T):
	(n, m) = map(int, input().split())
	mz = [list('#' + input().strip() + '#') for _ in range(n)]
	mz = [['#'] * (m + 2)] + mz + [['#'] * (m + 2)]
	ok = True
	g = 0
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if mz[i][j] == 'B':
				for (dy, dx) in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
					(y, x) = (i + dy, j + dx)
					if mz[y][x] == '.':
						if y == n and x == m:
							ok = False
						mz[y][x] = '#'
					elif mz[y][x] == 'G':
						ok = False
						break
			elif mz[i][j] == 'G':
				g += 1
	if g == 0:
		print('Yes')
		continue
	if not ok:
		print('No')
		continue
	visited = {}
	q = deque()
	q.append([n, m])
	while len(q) > 0:
		(y, x) = q.popleft()
		if mz[y][x] == 'G':
			g -= 1
		for (dy, dx) in [[-1, 0], [1, 0], [0, -1], [0, 1]]:
			(ny, nx) = (y + dy, x + dx)
			if (ny, nx) not in visited and mz[ny][nx] != '#':
				visited[ny, nx] = True
				q.append([ny, nx])
	print('Yes' if g == 0 else 'No')


from sys import setrecursionlimit as srl
srl(10 ** 5)
DIR = [(-1, 0), (1, 0), (0, -1), (0, 1)]
WALL = '#'
GOOD_PERSON = 'G'
BAD_PERSON = 'B'

def dfs(i, j):
	if i > n or i == 0 or j > m or (j == 0):
		return
	used[i][j] = 1
	for (di, dj) in DIR:
		if not used[i + di][j + dj] and a[i + di][j + dj] != WALL:
			dfs(i + di, j + dj)
tests = int(input())
for t in range(tests):
	(n, m) = list(map(int, input().split()))
	a = [['#'] * (m + 2)] + [list(WALL + input() + WALL) for i in range(n)] + [[WALL] * (m + 2)]
	(used, ok) = ([[0] * (m + 2) for i in range(n + 2)], True)
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if a[i][j] == BAD_PERSON:
				for (di, dj) in DIR:
					if a[i + di][j + dj] == GOOD_PERSON:
						ok = False
					elif a[i + di][j + dj] != BAD_PERSON:
						a[i + di][j + dj] = WALL
	if a[n][m] != WALL:
		dfs(n, m)
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if a[i][j] == GOOD_PERSON and (not used[i][j]):
				ok = False
	print('Yes' if ok else 'No')


import sys, math
input = sys.stdin.readline

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input().strip()

def listStr():
	return list(input().strip())
import collections as col
import math
from types import GeneratorType

def solve():

	def bootstrap(f, stack=[]):

		def wrappedfunc(*args, **kwargs):
			if stack:
				return f(*args, **kwargs)
			else:
				to = f(*args, **kwargs)
				while True:
					if type(to) is GeneratorType:
						stack.append(to)
						to = next(to)
					else:
						stack.pop()
						if not stack:
							break
						to = stack[-1].send(to)
				return to
		return wrappedfunc

	@bootstrap
	def dfs(graph, visited, node):
		if node not in visited:
			visited.add(node)
		for neighbour in graph[node]:
			if neighbour not in visited:
				yield dfs(graph, visited, neighbour)
		yield visited
	(N, M) = getInts()
	grid = []
	graph = col.defaultdict(set)
	G_count = 0
	for n in range(N):
		grid.append(listStr())
		G_count += grid[n].count('G')
	if G_count == 0:
		return 'Yes'
	for n in range(N):
		for m in range(M):
			flag1 = n > 0 and grid[n - 1][m] == 'B'
			flag2 = n < N - 1 and grid[n + 1][m] == 'B'
			flag3 = m > 0 and grid[n][m - 1] == 'B'
			flag4 = m < M - 1 and grid[n][m + 1] == 'B'
			if flag1 or flag2 or flag3 or flag4:
				if grid[n][m] == 'G':
					return 'No'
				if n == N - 1 and m == M - 1:
					return 'No'
				if grid[n][m] == 'B':
					continue
				assert grid[n][m] in ('.', '#')
				grid[n][m] = '#'
	for n in range(N):
		for m in range(M):
			if n > 0 and grid[n - 1][m] != '#':
				graph[n, m].add((n - 1, m))
			if n < N - 1 and grid[n + 1][m] != '#':
				graph[n, m].add((n + 1, m))
			if m > 0 and grid[n][m - 1] != '#':
				graph[n, m].add((n, m - 1))
			if m < M - 1 and grid[n][m + 1] != '#':
				graph[n, m].add((n, m + 1))
	visited = dfs(graph, set(), (N - 1, M - 1))
	G_count2 = 0
	for (n, m) in visited:
		if grid[n][m] == 'B':
			return 'No'
		if grid[n][m] == 'G':
			G_count2 += 1
	return 'Yes' if G_count2 == G_count else 'No'
for _ in range(getInt()):
	print(solve())


def checker(labr, n, m):
	taken = set()
	to_take = set()
	to_take.add(tuple([n - 1, m - 1]))
	amm = 0
	while len(to_take) > 0:
		i = to_take.pop()
		taken.add(i)
		if i[0] - 1 >= 0 and labr[i[0] - 1][i[1]] != '#' and (not (i[0] - 1, i[1]) in taken) and (not (i[0] - 1, i[1]) in to_take):
			if labr[i[0] - 1][i[1]] == 'G':
				amm += 1
			to_take.add(tuple([i[0] - 1, i[1]]))
		if i[1] - 1 >= 0 and labr[i[0]][i[1] - 1] != '#' and (not (i[0], i[1] - 1) in taken) and (not (i[0], i[1] - 1) in to_take):
			if labr[i[0]][i[1] - 1] == 'G':
				amm += 1
			to_take.add(tuple([i[0], i[1] - 1]))
		if i[0] + 1 < n and labr[i[0] + 1][i[1]] != '#' and (not (i[0] + 1, i[1]) in taken) and (not (i[0] + 1, i[1]) in to_take):
			if labr[i[0] + 1][i[1]] == 'G':
				amm += 1
			to_take.add(tuple([i[0] + 1, i[1]]))
		if i[1] + 1 < m and labr[i[0]][i[1] + 1] != '#' and (not (i[0], i[1] + 1) in taken) and (not (i[0], i[1] + 1) in to_take):
			if labr[i[0]][i[1] + 1] == 'G':
				amm += 1
			to_take.add(tuple([i[0], i[1] + 1]))
	return amm

def main():
	(n, m) = map(int, input().split())
	labr = []
	for i in range(n):
		line = list(input())
		labr.append(line)
	good = 0
	for i in range(n):
		for k in range(m):
			if labr[i][k] == 'G':
				good += 1
			if labr[i][k] == 'B':
				if i - 1 >= 0:
					if labr[i - 1][k] == 'G':
						print('No')
						return
					elif labr[i - 1][k] == 'B':
						pass
					else:
						labr[i - 1][k] = '#'
				if i + 1 < n:
					if labr[i + 1][k] == 'G':
						print('No')
						return
					elif labr[i + 1][k] == 'B':
						pass
					else:
						labr[i + 1][k] = '#'
				if k - 1 >= 0:
					if labr[i][k - 1] == 'G':
						print('No')
						return
					elif labr[i][k - 1] == 'B':
						pass
					else:
						labr[i][k - 1] = '#'
				if k + 1 < m:
					if labr[i][k + 1] == 'G':
						print('No')
						return
					elif labr[i][k + 1] == 'B':
						pass
					else:
						labr[i][k + 1] = '#'
	if labr[n - 1][m - 1] == '#':
		if good > 0:
			print('No')
			return
		else:
			print('Yes')
			return
	amm = checker(labr, n, m)
	if amm == good:
		print('Yes')
	else:
		print('No')
t = int(input())
for i in range(t):
	main()


import sys
input = sys.stdin.buffer.readline

def main():
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, input().split())
		M = [list(str(input())[2:m + 2]) for _ in range(n)]
		M = [['#'] * m] + M + [['#'] * m]
		M = [['#'] + c + ['#'] for c in M]
		B = []
		G = []
		flag1 = True
		for i in range(1, n + 1):
			for j in range(1, m + 1):
				if M[i][j] == 'B':
					for (di, dj) in ((-1, 0), (1, 0), (0, -1), (0, 1)):
						(ni, nj) = (i + di, j + dj)
						if 1 <= ni <= n and 1 <= nj <= m:
							if M[ni][nj] == '.':
								M[ni][nj] = '#'
							if M[ni][nj] == 'G':
								flag1 = False
								break
					B.append((i, j))
				if M[i][j] == 'G':
					G.append((i, j))
		if not flag1:
			print('No')
			continue
		if len(G) > 0 and M[n][m] == '#':
			print('No')
			continue
		s = []
		s.append((n, m))
		visit = [[-1] * (m + 2) for _ in range(n + 2)]
		visit[n][m] = 0
		while s:
			(y, x) = s.pop()
			for (dy, dx) in ((-1, 0), (1, 0), (0, -1), (0, 1)):
				(ny, nx) = (y + dy, x + dx)
				if visit[ny][nx] == -1 and M[ny][nx] != '#':
					visit[ny][nx] = visit[y][x] + 1
					s.append((ny, nx))
		flag = True
		for (sy, sx) in G:
			if visit[sy][sx] == -1:
				flag = False
				break
		if flag:
			print('Yes')
		else:
			print('No')
main()


def neighbours(a, b, maze, n, m):
	if maze[a][b] == '#':
		return []
	k = [(0, 1), (1, 0), (-1, 0), (0, -1)]
	ans = []
	for (u, v) in k:
		if 0 <= u + a < n and 0 <= v + b < m:
			if maze[u + a][v + b] != '#':
				ans.append((u + a, v + b))
	return ans

def bfs(maze, n, m, gcount):
	findcount = 0
	visited = [[False for i in range(m)] for j in range(n)]
	visited[n - 1][m - 1] = True
	queue = [(n - 1, m - 1)]
	while queue:
		(a, b) = queue.pop()
		if maze[a][b] == 'G':
			findcount += 1
		for (p, q) in neighbours(a, b, maze, n, m):
			if visited[p][q] == False:
				visited[p][q] = True
				queue.append((p, q))
	if findcount == gcount:
		return True
	else:
		return False
t = int(input())
for _ in range(t):
	(n, m) = [int(c) for c in input().split()]
	maze = []
	gcount = 0
	for i in range(n):
		arr = [c for c in input()]
		maze.append(arr)
		gcount += arr.count('G')
	ans = True
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'B':
				for (u, v) in neighbours(i, j, maze, n, m):
					if maze[u][v] == '.':
						maze[u][v] = '#'
					elif maze[u][v] == 'G':
						ans = False
	if bfs(maze, n, m, gcount) and ans:
		print('Yes')
	else:
		print('No')


import sys

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

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

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
from collections import deque

def solve(n, m, a):
	good = []
	bad = []
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'G':
				good.append((i, j))
			if a[i][j] == 'B':
				bad.append((i, j))
	end_i = n - 1
	end_j = m - 1
	id_i = [-1, 0, 1, 0]
	id_j = [0, 1, 0, -1]
	ok = lambda x, y: x >= 0 and x < n and (y >= 0) and (y < m)
	for (bi, bj) in bad:
		for k in range(4):
			bii = bi + id_i[k]
			bjj = bj + id_j[k]
			if not ok(bii, bjj):
				continue
			for (gi, gj) in good:
				if bii == gi and bjj == gj:
					return False
			a[bii][bjj] = '#'
	cnt = 0
	visited = [[False] * m for _ in range(n)]
	if a[end_i][end_j] == '#' and len(good) > 0:
		return False
	q = deque()
	q.append((end_i, end_j))
	visited[end_i][end_j] = True
	while q:
		(vi, vj) = q.popleft()
		if a[vi][vj] == 'G':
			cnt += 1
		for k in range(4):
			vii = vi + id_i[k]
			vjj = vj + id_j[k]
			if not ok(vii, vjj):
				continue
			if a[vii][vjj] != '#' and (not visited[vii][vjj]):
				q.append((vii, vjj))
				visited[vii][vjj] = True
	return cnt == len(good)

def main():
	for _ in range(ri()):
		(n, m) = ria()
		a = []
		for _ in range(n):
			a.append([si for si in rs()])
		wi('Yes' if solve(n, m, a) else 'No')
main()


T = int(input().strip())
for t in range(T):
	(n, m) = list(map(int, input().split()))
	field = [[1] * (m + 2) for _ in range(n + 2)]
	bads = []
	goods = []
	for row in range(n):
		cr = input().strip()
		for (col, cell) in enumerate(cr):
			if cell == '#':
				field[row + 1][col + 1] = 1
			elif cell == 'B':
				bads.append((row + 1, col + 1))
				field[row + 1][col + 1] = 0
			elif cell == 'G':
				goods.append((row + 1, col + 1))
				field[row + 1][col + 1] = 0
			else:
				field[row + 1][col + 1] = 0
	if len(goods) == 0:
		print('Yes')
		continue
	for b in bads:
		for (shiftx, shifty) in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
			field[b[0] + shiftx][b[1] + shifty] = 1
	stk = [(n, m)]
	if field[n][m] == 1:
		print('No')
		continue
	start = 0
	field[n][m] = 2
	while start < len(stk):
		b = stk[start]
		for (shiftx, shifty) in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
			if field[b[0] + shiftx][b[1] + shifty] == 0:
				field[b[0] + shiftx][b[1] + shifty] = 2
				stk.append((b[0] + shiftx, b[1] + shifty))
		start += 1
	good = True
	for b in goods:
		if field[b[0]][b[1]] != 2:
			good = False
			break
	if good:
		print('Yes')
	else:
		print('No')


import collections
import sys
input = sys.stdin.readline
from collections import defaultdict

def bfs(i, j):
	gcount = 0
	bcount = 0
	queue = collections.deque([(i, j)])
	visited[i][j] = 1
	while queue:
		(i, j) = queue.popleft()
		for (a, b) in [(i + 1, j), (i - 1, j), (i, j + 1), (i, j - 1)]:
			if a == -1 or a == n or b == -1 or (b == m) or visited[a][b] or (grid[a][b] == '#'):
				continue
			if grid[a][b] == 'G':
				gcount += 1
			if grid[a][b] == 'B':
				bcount += 1
			visited[a][b] += 1
			queue.append((a, b))
	return (gcount, bcount)
t = int(input())
for i in range(t):
	grid = []
	(n, m) = map(int, input().split())
	visited = [[0] * m for _ in range(n)]
	for j in range(n):
		row = [i for i in input() if i != '\n']
		grid.append(row)
	good_count = 0
	for j in range(n):
		for k in range(m):
			if grid[j][k] == 'B':
				if 0 <= k + 1 and k + 1 < m and (grid[j][k + 1] == '.'):
					grid[j][k + 1] = '#'
				if 0 <= k - 1 and k - 1 < m and (grid[j][k - 1] == '.'):
					grid[j][k - 1] = '#'
				if 0 <= j + 1 and j + 1 < n and (grid[j + 1][k] == '.'):
					grid[j + 1][k] = '#'
				if 0 <= j - 1 and j - 1 < n and (grid[j - 1][k] == '.'):
					grid[j - 1][k] = '#'
			if grid[j][k] == 'G':
				good_count += 1
	if grid[-1][-1] == '#':
		if good_count == 0:
			print('Yes')
		else:
			print('No')
		continue
	(output, ans) = bfs(n - 1, m - 1)
	if output == good_count and ans == 0:
		print('Yes')
	else:
		print('No')


import sys
read = input
mi = lambda : map(int, read().split())
cin = lambda : int(read())
li = lambda : list(mi())
for _ in range(cin()):
	(n, m) = mi()
	a = []
	nz = 0
	for i in range(n):
		a.append(list(input()))
		for el in a[-1]:
			if el == 'G':
				nz += 1
	if a[-1][-1] == 'B':
		print('No')
		continue

	def isnb(a, i, j, m, n):
		if i + 1 < n and a[i + 1][j] == 'B':
			return True
		if i - 1 >= 0 and a[i - 1][j] == 'B':
			return True
		if j + 1 < m and a[i][j + 1] == 'B':
			return True
		if j - 1 >= 0 and a[i][j - 1] == 'B':
			return True
		return False
	vz = 0
	vis = [[0 for i in range(m)] for j in range(n)]
	st = [[n - 1, m - 1]]
	vis[n - 1][m - 1] = 1
	while st:
		(i, j) = (st[-1][0], st[-1][1])
		st.pop()
		if isnb(a, i, j, m, n):
			continue
		if a[i][j] == 'G':
			vz += 1
		if i + 1 < n and vis[i + 1][j] == 0 and (a[i + 1][j] != '#'):
			st.append([i + 1, j])
			vis[i + 1][j] = 1
		if j + 1 < m and vis[i][j + 1] == 0 and (a[i][j + 1] != '#'):
			st.append([i, j + 1])
			vis[i][j + 1] = 1
		if i - 1 >= 0 and vis[i - 1][j] == 0 and (a[i - 1][j] != '#'):
			st.append([i - 1, j])
			vis[i - 1][j] = 1
		if j - 1 >= 0 and vis[i][j - 1] == 0 and (a[i][j - 1] != '#'):
			st.append([i, j - 1])
			vis[i][j - 1] = 1
	if nz != vz:
		print('No')
	else:
		print('Yes')


t = int(input())
for test in range(t):
	(n, m) = [int(x) for x in input().split()]
	mat = []
	mat.append(['#' for i in range(m + 2)])
	for i in range(n):
		x = ['#'] + list(input()) + ['#']
		mat.append(x)
	mat.append(['#' for i in range(m + 2)])
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if mat[i][j] == 'B':
				if mat[i - 1][j] == '.':
					mat[i - 1][j] = '#'
				if mat[i + 1][j] == '.':
					mat[i + 1][j] = '#'
				if mat[i][j - 1] == '.':
					mat[i][j - 1] = '#'
				if mat[i][j + 1] == '.':
					mat[i][j + 1] = '#'
	que = []
	dp = [[False for i in range(m + 2)] for j in range(n + 2)]
	if mat[n][m] == '.':
		que.append((n, m))
		dp[n][m] = True
	while len(que) > 0:
		x = que.pop()
		i = x[0]
		j = x[1]
		if i - 1 >= 0 and dp[i - 1][j] == False and (mat[i - 1][j] != '#'):
			que.append((i - 1, j))
			dp[i - 1][j] = True
		if i + 1 <= n and dp[i + 1][j] == False and (mat[i + 1][j] != '#'):
			que.append((i + 1, j))
			dp[i + 1][j] = True
		if j - 1 >= 0 and dp[i][j - 1] == False and (mat[i][j - 1] != '#'):
			que.append((i, j - 1))
			dp[i][j - 1] = True
		if j + 1 <= m and dp[i][j + 1] == False and (mat[i][j + 1] != '#'):
			que.append((i, j + 1))
			dp[i][j + 1] = True
	flag = 0
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if mat[i][j] == 'G' and dp[i][j] == False or (mat[i][j] == 'B' and dp[i][j] == True):
				flag = 1
				break
	if flag == 1:
		print('No')
	else:
		print('Yes')


from __future__ import division, print_function
import sys
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip
import os, sys, bisect, copy
from collections import defaultdict, Counter, deque
if os.path.exists('in.txt'):
	sys.stdin = open('in.txt', 'r')
if os.path.exists('out.txt'):
	sys.stdout = open('out.txt', 'w')

def input():
	return sys.stdin.readline()

def mapi(arg=0):
	return map(int if arg == 0 else str, input().split())
sys.setrecursionlimit(10 ** 4)
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
for _ in range(int(input())):
	(n, m) = mapi()
	mat = []
	for i in range(n):
		mat.append(list(input().strip()))
	good = 0
	for i in range(n):
		good += mat[i].count('G')
	if good == 0:
		print('Yes')
		continue
	vis = [[0] * m for i in range(n)]
	f = 0
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 'G':
				for k in range(4):
					xx = i + dx[k]
					yy = j + dy[k]
					if 0 <= xx < n and 0 <= yy < m and (mat[xx][yy] == 'B'):
						f = 1
						break
				if f:
					break
		if f:
			break
	if f:
		print('No')
		continue
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 'B':
				for k in range(4):
					xx = i + dx[k]
					yy = j + dy[k]
					if 0 <= xx < n and 0 <= yy < m and (mat[xx][yy] == '.' or mat[xx][yy] == 'G'):
						mat[xx][yy] = '#'

	def dfs(i, j):
		if mat[i][j] == '#':
			return
		vis[i][j] = 1
		for k in range(4):
			xx = i + dx[k]
			yy = j + dy[k]
			if 0 <= xx < n and 0 <= yy < m and (mat[xx][yy] != '#') and (vis[xx][yy] == 0):
				dfs(xx, yy)
	dfs(n - 1, m - 1)
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 'G' and vis[i][j] == 0:
				f = 1
				break
		if f:
			break
	print('No' if f else 'Yes')


def dfs(r, c, mat, visited):
	if mat[r][c] != '#' and (not visited[r][c]):
		sum = 0
		if mat[r][c] == 'G':
			sum += 1
		visited[r][c] = True
		if r - 1 >= 0:
			sum += dfs(r - 1, c, mat, visited)
		if r + 1 < len(mat):
			sum += dfs(r + 1, c, mat, visited)
		if c - 1 >= 0:
			sum += dfs(r, c - 1, mat, visited)
		if c + 1 < len(mat[r]):
			sum += dfs(r, c + 1, mat, visited)
		return sum
	else:
		return 0
times = int(input())
for asdf in range(times):
	(r, c) = [int(i) for i in input().split()]
	mat = []
	visited = []
	for i in range(r):
		visited.append([])
		for j in range(c):
			visited[i].append(False)
	for i in range(r):
		mat.append([str(i) for i in input()])
	works = True
	gcnt = 0
	for i in range(r):
		for j in range(c):
			if mat[i][j] == 'B':
				if i + 1 < r and mat[i + 1][j] == '.':
					mat[i + 1][j] = '#'
				elif i + 1 < r and mat[i + 1][j] == 'G':
					works = False
				if i - 1 >= 0:
					if mat[i - 1][j] == '.':
						mat[i - 1][j] = '#'
					elif mat[i - 1][j] == 'G':
						works = False
				if j + 1 < c:
					if mat[i][j + 1] == '.':
						mat[i][j + 1] = '#'
					elif mat[i][j + 1] == 'G':
						works = False
				if j - 1 >= 0:
					if mat[i][j - 1] == '.':
						mat[i][j - 1] = '#'
					elif mat[i][j - 1] == 'G':
						works = False
			elif mat[i][j] == 'G':
				gcnt += 1
	if not works:
		print('No')
	elif dfs(r - 1, c - 1, mat, visited) == gcnt:
		print('Yes')
	else:
		print('No')


import sys
from collections import deque, Counter
from itertools import product
T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	bd = [list(input()) for _ in range(n)]
	gcc = 0
	for (i, j) in product(range(n), range(m)):
		if bd[i][j] == 'G':
			gcc += 1
		if bd[i][j] != 'B':
			continue
		for (r, c) in [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]:
			if 0 <= r < n and 0 <= c < m and (bd[r][c] == '.'):
				bd[r][c] = '#'
	(gc, bc) = (0, 0)
	vis = [[0] * m for _ in range(n)]
	q = deque([(n - 1, m - 1)])
	vis[n - 1][m - 1] = 1
	while q:
		(i, j) = q.popleft()
		if bd[i][j] == 'G':
			gc += 1
		if bd[i][j] == 'B':
			bc += 1
		for (r, c) in [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]:
			if 0 <= r < n and 0 <= c < m and (bd[r][c] != '#') and (bd[i][j] != '#') and (not vis[r][c]):
				vis[r][c] = 1
				q.append((r, c))
	print('Yes' if gcc == gc and bc == 0 else 'No')


import io
import os
from collections import deque

def bfs(source, getNbr):
	q = deque([source])
	dist = {source: 0}
	while q:
		node = q.popleft()
		assert node in dist
		d = dist[node]
		for nbr in getNbr(node):
			if nbr not in dist:
				q.append(nbr)
				dist[nbr] = d + 1
	return dist

def solve(R, C, grid):
	drdc = [(-1, 0), (0, -1), (0, 1), (1, 0)]

	def getNbr(node):
		(r, c) = node
		for (dr, dc) in drdc:
			nr = r + dr
			nc = c + dc
			if 0 <= nr < R and 0 <= nc < C:
				yield (nr, nc)

	def getWalkableNbr(node):
		for (nr, nc) in getNbr(node):
			if grid[nr][nc] != '#':
				yield (nr, nc)
	goodCount = 0
	for r in range(R):
		for c in range(C):
			if grid[r][c] == 'G':
				goodCount += 1
			if grid[r][c] == 'B':
				for (nr, nc) in getNbr((r, c)):
					if grid[nr][nc] == 'G':
						return 'No'
					if grid[nr][nc] == 'B':
						continue
					assert grid[nr][nc] in '.#'
					grid[nr][nc] = '#'
	goodLeave = 0
	badLeave = 0
	if grid[R - 1][C - 1] != '#':
		source = (R - 1, C - 1)
		dist = bfs(source, getWalkableNbr)
		for (r, c) in dist.keys():
			if grid[r][c] == 'G':
				goodLeave += 1
			if grid[r][c] == 'B':
				badLeave += 1
	if goodLeave == goodCount and badLeave == 0:
		return 'Yes'
	return 'No'
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
T = int(input())
for t in range(T):
	(N, M) = [int(x) for x in input().split()]
	grid = [list(input().decode().rstrip()) for i in range(N)]
	ans = solve(N, M, grid)
	print(ans)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def bfs(graph, start=0):
	used = [False] * len(graph)
	used[start] = True
	q = [start]
	for v in q:
		for w in graph[v]:
			if not used[w]:
				used[w] = True
				q.append(w)

def layers(graph, start=0):
	used = [False] * len(graph)
	used[start] = True
	(q, ret) = ([start], [])
	while q:
		nq = []
		ret.append(q)
		for v in q:
			for w in graph[v]:
				if not used[w]:
					used[w] = True
					nq.append(w)
		q = nq
	return ret

def dfs(graph, start=0):
	n = len(graph)
	dp = [0] * n
	(visited, finished) = ([False] * n, [False] * n)
	stack = [start]
	while stack:
		start = stack[-1]
		if not visited[start]:
			visited[start] = True
			for child in graph[start]:
				if not visited[child]:
					stack.append(child)
		else:
			stack.pop()
			dp[start] += 1
			for child in graph[start]:
				if finished[child]:
					dp[start] += dp[child]
			finished[start] = True
	return visited
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	grid = []
	for __ in range(n):
		s = [k for k in input()]
		grid += [s]
	check = []
	anticheck = []
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 'G':
				check += [i * m + j + 1]
			if grid[i][j] == 'B':
				anticheck += [i * m + j + 1]
				if i != n - 1:
					if grid[i + 1][j] == '.':
						grid[i + 1][j] = '#'
				if i != 0:
					if grid[i - 1][j] == '.':
						grid[i - 1][j] = '#'
				if j != 0:
					if grid[i][j - 1] == '.':
						grid[i][j - 1] = '#'
				if j != m - 1:
					if grid[i][j + 1] == '.':
						grid[i][j + 1] = '#'
	graph = [[] for ___ in range(n * m + 1)]
	for i in range(n):
		for j in range(m):
			if grid[i][j] == '#':
				continue
			current = i * m + j + 1
			if i != 0:
				next_cell = grid[i - 1][j]
				if next_cell != '#':
					graph[current] += [(i - 1) * m + j + 1]
			if i != n - 1:
				next_cell = grid[i + 1][j]
				if next_cell != '#':
					graph[current] += [(i + 1) * m + j + 1]
			if j != 0:
				next_cell = grid[i][j - 1]
				if next_cell != '#':
					graph[current] += [i * m + (j - 1) + 1]
			if j != m - 1:
				next_cell = grid[i][j + 1]
				if next_cell != '#':
					graph[current] += [i * m + (j + 1) + 1]
	vis = dfs(graph, n * m)
	pos = True
	for i in check:
		if not vis[i]:
			pos = False
			break
	for i in anticheck:
		if vis[i]:
			pos = False
			break
	print('Yes' if pos else 'No')


import sys

def input():
	return sys.stdin.readline().rstrip()
dxy = ((-1, 0), (0, -1), (1, 0), (0, 1))

class UnionFind:

	def __init__(self, n):
		self.n = n
		self.parents = [-1] * n

	def find(self, x):
		if self.parents[x] < 0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self, x, y):
		x = self.find(x)
		y = self.find(y)
		if x == y:
			return
		if self.parents[x] > self.parents[y]:
			(x, y) = (y, x)
		self.parents[x] += self.parents[y]
		self.parents[y] = x

	def size(self, x):
		return -self.parents[self.find(x)]

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def members(self, x):
		root = self.find(x)
		return [i for i in range(self.n + 1) if self.find(i) == root]

	def roots(self):
		return [i for (i, x) in enumerate(self.parents) if x < 0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()}

def slv():
	(n, m) = map(int, input().split())
	S = [list(input()) for i in range(n)]
	for i in range(n):
		for j in range(m):
			if S[i][j] == 'G':
				for (di, dj) in dxy:
					if 0 <= i + di < n and 0 <= j + dj < m and (S[i + di][j + dj] == 'B'):
						print('No')
						return
			elif S[i][j] == 'B':
				for (di, dj) in dxy:
					if 0 <= i + di < n and 0 <= j + dj < m and (S[i + di][j + dj] == '.'):
						S[i + di][j + dj] = '#'
	dsu = UnionFind(n * m)
	for i in range(n):
		for j in range(m):
			if S[i][j] == '#':
				continue
			p = m * i + j
			for (di, dj) in dxy:
				(i_1, j_1) = (i + di, j + dj)
				if 0 <= i_1 < n and 0 <= j_1 < m and (S[i_1][j_1] != '#'):
					q = m * i_1 + j_1
					dsu.union(p, q)
	for i in range(n):
		for j in range(m):
			if S[i][j] == 'B':
				p = m * i + j
				q = m * n - 1
				if dsu.same(p, q) == True:
					print('No')
					return
			elif S[i][j] == 'G':
				p = m * i + j
				q = m * n - 1
				if dsu.same(p, q) == False:
					print('No')
					return
	print('Yes')
	return

def main():
	t = int(input())
	for _ in range(t):
		slv()
	return
main()


t = int(input())

def find_occur(grid):
	g_count = 0
	b_count = 0
	hash_count = 0
	for r in grid:
		for c in r:
			if c == 'G':
				g_count += 1
			elif c == 'B':
				b_count += 1
			elif c == '#':
				hash_count += 1
	return (g_count, b_count, hash_count)

def bound_B(grid):
	flag = True
	hash_updates = 0
	updates = [(0, 0), (-1, 0), (1, 0), (0, 1), (0, -1)]
	update_list = []
	for r in range(len(grid)):
		for c in range(len(grid[0])):
			if grid[r][c] == 'B':
				for up in updates:
					if r + up[0] >= 0 and r + up[0] < len(grid) and (c + up[1] >= 0) and (c + up[1] < len(grid[0])):
						update_list.append((r + up[0], c + up[1]))
	for (r, c) in update_list:
		if grid[r][c] == 'G':
			flag = False
			break
		else:
			grid[r][c] = '#'
			hash_updates += 1
	return (flag, grid, hash_updates)

def findch(grid, ch, depth):
	updates = [(-1, 0), (1, 0), (0, 1), (0, -1)]
	queue = [(len(grid) - 1, len(grid[0]) - 1)]
	visited = set()
	g_count = 0
	if grid[len(grid) - 1][len(grid[0]) - 1] == '#':
		return g_count
	visited.add((len(grid) - 1, len(grid[0]) - 1))
	while len(queue) > 0:
		(r, c) = queue.pop(0)
		if grid[r][c] == ch:
			g_count += 1
		if depth == 0:
			continue
		for up in updates:
			if r + up[0] >= 0 and r + up[0] < len(grid) and (c + up[1] >= 0) and (c + up[1] < len(grid[0])):
				if grid[r + up[0]][c + up[1]] != '#':
					if (r + up[0], c + up[1]) not in visited:
						queue.append((r + up[0], c + up[1]))
						visited.add((r + up[0], c + up[1]))
		depth -= 1
	return g_count
for i in range(t):
	(n, m) = [int(x) for x in input().split(' ')]
	grid = []
	for j in range(n):
		temp = list(input())
		grid.append(temp)
	(g_count, b_count, hash_count) = find_occur(grid)
	if g_count == 0:
		if grid[-1][-1] == '#' or grid[-1][-1] == '.':
			print('Yes')
			continue
		b_found = findch(grid, 'B', 1)
		if b_found > 0:
			print('No')
			continue
		print('Yes')
		continue
	if grid[-1][-1] == '#':
		print('No')
		continue
	(status, grid, hash_updates) = bound_B(grid)
	if status == False:
		print('No')
		continue
	hash_count += hash_updates
	if hash_count == 0:
		print('Yes')
		continue
	g_found = findch(grid, 'G', 10000)
	if g_count == g_found:
		print('Yes')
	else:
		print('No')


import sys
input = sys.stdin.readline
(T,) = map(int, input().split())
for _ in range(T):
	(N, M) = map(int, input().split())
	X = []
	gn = 0
	for _ in range(N):
		s = input().strip()
		X.append(s)
		gn += s.count('G')
	stack = [(N - 1, M - 1)]
	vs = set([(N - 1, M - 1)])
	ff = 0
	r = 0
	while stack:
		(a, b) = stack.pop()
		cu = X[a][b]
		cs = []
		if a != N - 1:
			cs.append((a + 1, b))
		if a != 0:
			cs.append((a - 1, b))
		if b != M - 1:
			cs.append((a, b + 1))
		if b != 0:
			cs.append((a, b - 1))
		f = 0
		for (c, d) in cs:
			if X[c][d] == 'B':
				f = 1
				break
		if f:
			if cu == 'G':
				ff = 1
				break
			continue
		if cu == 'G':
			r += 1
		for (c, d) in cs:
			if (c, d) in vs:
				continue
			if X[c][d] != '#':
				stack.append((c, d))
				vs.add((c, d))
	if ff or r != gn:
		print('No')
	else:
		print('Yes')


wer = int(input())
for ewr in range(wer):
	(n, m) = list(map(int, input().split(' ')))
	temp = []
	cou = 0
	for i in range(n):
		t1 = input()
		ig = t1.find('G')
		if ig != -1:
			cou = 1
		temp.append(list(t1))
	if cou == 0:
		print('Yes')
		continue
	flag = 0
	for i in range(n):
		for j in range(m):
			if temp[i][j] == 'B':
				if i > 0 and flag == 0:
					if temp[i - 1][j] == 'G':
						flag = 1
						break
					elif temp[i - 1][j] != 'B':
						temp[i - 1][j] = '#'
				if i + 1 < n and flag == 0:
					if temp[i + 1][j] == 'G':
						flag = 1
						break
					elif temp[i + 1][j] != 'B':
						temp[i + 1][j] = '#'
				if j > 0 and flag == 0:
					if temp[i][j - 1] == 'G':
						flag = 1
						break
					elif temp[i][j - 1] != 'B':
						temp[i][j - 1] = '#'
				if j + 1 < m and flag == 0:
					if temp[i][j + 1] == 'G':
						flag = 1
						break
					elif temp[i][j + 1] != 'B':
						temp[i][j + 1] = '#'
			if flag == 1:
				break
		if flag == 1:
			break
	if flag == 1 or temp[n - 1][m - 1] == '#':
		print('No')
		continue
	li = []
	li.append([n - 1, m - 1])
	flag = 0
	while len(li) > 0:
		(i, j) = li.pop(0)
		if i > 0:
			if temp[i - 1][j] != '#' and temp[i - 1][j] != '1':
				temp[i - 1][j] = '1'
				li.append([i - 1, j])
		if i + 1 < n:
			if temp[i + 1][j] != '#' and temp[i + 1][j] != '1':
				temp[i + 1][j] = '1'
				li.append([i + 1, j])
		if j > 0:
			if temp[i][j - 1] != '#' and temp[i][j - 1] != '1':
				temp[i][j - 1] = '1'
				li.append([i, j - 1])
		if j + 1 < m:
			if temp[i][j + 1] != '#' and temp[i][j + 1] != '1':
				temp[i][j + 1] = '1'
				li.append([i, j + 1])
	for i in range(n):
		tr = ''.join(temp[i])
		ind = tr.find('G')
		if ind != -1:
			flag = 1
			break
	if flag == 1:
		print('No')
	else:
		print('Yes')


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	grid = []
	for _ in range(n):
		grid.append(list(input()))

	def get_ns(i, j):
		ns = []
		for (s_x, s_y) in [(-1, 0), (1, 0), (0, 1), (0, -1)]:
			if 0 <= i + s_x < n and 0 <= j + s_y < m and (grid[i + s_x][j + s_y] != '#'):
				ns.append((i + s_x, j + s_y))
		return ns

	def solve():
		good = set()
		for i in range(n):
			for j in range(m):
				if grid[i][j] == 'G':
					good.add((i, j))
				if grid[i][j] == 'B':
					for (x, y) in get_ns(i, j):
						if grid[x][y] == 'G':
							return False
						if grid[x][y] == '.':
							grid[x][y] = '#'
		if not good:
			return True
		if grid[n - 1][m - 1] not in ['.', 'G']:
			return False
		stack = [(n - 1, m - 1)]
		visited = set()
		while stack:
			(x, y) = stack.pop()
			if (x, y) in good:
				good.remove((x, y))
			for ns in get_ns(x, y):
				if ns not in visited:
					visited.add(ns)
					stack.append(ns)
		if good:
			return False
		return True
	ans = solve()
	if ans:
		print('Yes')
	else:
		print('No')


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import factorial
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

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

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

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)
mod = 998244353
INF = float('inf')

def main():
	for _ in range(N()):
		(n, m) = RL()
		gp = [list(input()) for _ in range(n)]
		nex = [[1, 0], [0, 1], [-1, 0], [0, -1]]
		gd = 0
		bad = 0
		tag = False
		for i in range(n):
			for j in range(m):
				if gp[i][j] == 'G':
					gd += 1
				if gp[i][j] == 'B':
					bad += 1
					for (xx, yy) in nex:
						if -1 < xx + i < n and -1 < yy + j < m and (gp[xx + i][yy + j] == '.'):
							gp[xx + i][yy + j] = '#'
						if -1 < xx + i < n and -1 < yy + j < m and (gp[xx + i][yy + j] == 'G'):
							tag = True
		if gp[-1][-1] == 'B' or tag:
			print('No')
		elif gp[-1][-1] == '#':
			if gd != 0:
				print('No')
			else:
				print('Yes')
		else:
			q = deque()
			q.append((n - 1, m - 1))
			vis = [[0] * m for _ in range(n)]
			vis[-1][-1] = 1
			if gp[n - 1][m - 1] == 'G':
				gd -= 1
			while q:
				(px, py) = q.popleft()
				bd = 0
				for (xx, yy) in nex:
					(nx, ny) = (xx + px, yy + py)
					if -1 < nx < n and -1 < ny < m and (vis[nx][ny] == 0):
						vis[nx][ny] = 1
						if gp[nx][ny] == 'G':
							gd -= 1
						if gp[nx][ny] == 'B':
							bd += 1
						if gp[nx][ny] == '.' or gp[nx][ny] == 'G':
							q.append((nx, ny))
			print('Yes' if gd == 0 and bd == 0 else 'No')
main()


import os
import sys
from io import BytesIO, IOBase
import threading
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import ceil

def lcm(a, b):
	return a * b // gcd(a, b)

def inin():
	return int(input())

def inar():
	return list(map(int, input().split()))

def ar(element, size):
	return [element for i in range(size)]

def yes():
	print('Yes')

def no():
	print('No')
dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]

def dfs(i, j, visited):
	visited[i][j] = True
	for delta in range(4):
		x = j + dx[delta]
		y = i + dy[delta]
		if x >= 0 and y >= 0 and (x < m) and (y < n) and (visited[y][x] == False):
			if maze[y][x] == '.' or maze[y][x] == 'G':
				dfs(y, x, visited)
Gloc = []
Testcase = inin()
for _ in range(Testcase):
	Gloc = []
	(n, m) = inar()
	maze = ['' for i in range(n)]
	for i in range(n):
		maze[i] = list(input())
	pasapasi = False
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'G':
				Gloc.append((i, j))
			if maze[i][j] == 'B':
				for delta in range(4):
					x = j + dx[delta]
					y = i + dy[delta]
					if x >= 0 and y >= 0 and (x < m) and (y < n):
						if maze[y][x] == 'G':
							pasapasi = True
							break
						if maze[y][x] == '.':
							maze[y][x] = '#'
	if pasapasi:
		no()
	elif maze[n - 1][m - 1] == '#':
		if Gloc == []:
			yes()
		else:
			no()
	else:
		visited = [[False for j in range(m)] for i in range(n)]
		dfs(n - 1, m - 1, visited)
		cond = True
		for (i, j) in Gloc:
			cond = cond and visited[i][j]
		if cond:
			yes()
		else:
			no()


import collections
t = int(input())

def is_free(grid, vis, i, j):
	if (i, j) in vis:
		return False
	n = len(grid)
	m = len(grid[0])
	if i < 0 or i >= n or j < 0 or (j >= m):
		return False
	if grid[i][j] in ('#', 'B'):
		return False
	for (ii, jj) in ((i - 1, j), (i, j - 1), (i, j + 1), (i + 1, j)):
		if ii >= 0 and ii < n and (jj >= 0) and (jj < m) and (grid[ii][jj] == 'B'):
			return False
	return True
for _ in range(t):
	(n, m) = map(int, input().split())
	grid = [list(input()) for _ in range(n)]
	cnt = 0
	for row in grid:
		for cell in row:
			if cell == 'G':
				cnt += 1
	q = collections.deque([])
	vis = set()
	if is_free(grid, vis, n - 1, m - 1):
		q.append((n - 1, m - 1))
	while q:
		(i, j) = q.popleft()
		for (ii, jj) in ((i - 1, j), (i, j - 1), (i, j + 1), (i + 1, j)):
			if is_free(grid, vis, ii, jj):
				if grid[ii][jj] == 'G':
					cnt -= 1
				vis.add((ii, jj))
				q.append((ii, jj))
	print('Yes' if cnt == 0 else 'No')


a = input()
for x in range(int(a)):
	b = input().split(' ')
	grid = []
	list = []
	for i in range(int(b[0])):
		grid.append([])
		c = input()
		for j in range(int(b[1])):
			grid[i].append(c[j])
			if grid[i][j] == 'G':
				list.append([i, j])
	ans = 0
	for i in range(len(grid)):
		for j in range(len(grid[0])):
			if grid[i][j] == 'B':
				if i + 1 < len(grid):
					if grid[i + 1][j] == 'G':
						ans = 1
					elif grid[i + 1][j] != 'B':
						grid[i + 1][j] = '#'
				if i - 1 >= 0:
					if grid[i - 1][j] == 'G':
						ans = 1
					elif grid[i - 1][j] != 'B':
						grid[i - 1][j] = '#'
				if j + 1 < len(grid[0]):
					if grid[i][j + 1] == 'G':
						ans = 1
					elif grid[i][j + 1] != 'B':
						grid[i][j + 1] = '#'
				if j - 1 >= 0:
					if grid[i][j - 1] == 'G':
						ans = 1
					elif grid[i][j - 1] != 'B':
						grid[i][j - 1] = '#'
	if ans == 1:
		print('No')
	else:
		dict = {}
		for i in range(len(grid)):
			for j in range(len(grid[0])):
				tag = 0
				if grid[i][j] == 'G' or grid[i][j] == '.':
					l = -1
					q = -1
					if i - 1 >= 0:
						if grid[i - 1][j] != '#':
							l = grid[i - 1][j]
					if j - 1 >= 0:
						if grid[i][j - 1] != '#':
							q = grid[i][j - 1]
					if l != -1:
						grid[i][j] = l
						dict[l].append([i, j])
						if q != -1:
							if q != l:
								dict[l] += dict[q]
								for k in dict[q]:
									grid[k[0]][k[1]] = l
					elif q != -1:
						grid[i][j] = q
						dict[q].append([i, j])
					else:
						grid[i][j] = i * len(grid[0]) + j
						dict[i * len(grid[0]) + j] = [[i, j]]
		ans = 0
		for i in list:
			if grid[int(b[0]) - 1][int(b[1]) - 1] == grid[i[0]][i[1]]:
				ans += 1
			else:
				break
		if ans == len(list):
			print('Yes')
		else:
			print('No')


from collections import deque

def solve(n, m, mp):
	ngood = 0
	for r in range(n):
		for c in range(m):
			if mp[r][c] == 'B':
				for (dr, dc) in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
					(nr, nc) = (r + dr, c + dc)
					if 0 <= nr < n and 0 <= nc < m:
						if mp[nr][nc] == '.':
							mp[nr][nc] = '#'
						elif mp[nr][nc] == 'G':
							return False
			elif mp[r][c] == 'G':
				ngood += 1
	q = deque()
	seen = set()
	if mp[n - 1][m - 1] != '#':
		q.append((n - 1, m - 1))
		seen.add((n - 1, m - 1))
	while q:
		(r, c) = q.popleft()
		if mp[r][c] == 'G':
			ngood -= 1
		for (dr, dc) in [(-1, 0), (1, 0), (0, -1), (0, 1)]:
			(nr, nc) = (r + dr, c + dc)
			if 0 <= nr < n and 0 <= nc < m and (mp[nr][nc] in '.G') and ((nr, nc) not in seen):
				seen.add((nr, nc))
				q.append((nr, nc))
	return ngood == 0
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	mp = []
	for _ in range(n):
		mp.append(list(input()))
	print('Yes' if solve(n, m, mp) else 'No')


testing_mode = True
import sys, traceback
test_data = ''
final_output = ''

def input(input_format=0, multi=0):
	if multi > 0:
		return [input(input_format) for x in range(multi)]
	else:
		next_line = next(test_data, None).strip() if test_data else sys.stdin.readline()
		if input_format == 0:
			formatted_input = [next_line]
		elif input_format == 1:
			formatted_input = list(map(int, next_line.split()))
		elif input_format == 2:
			formatted_input = list(map(float, next_line.split()))
		elif input_format == 3:
			formatted_input = next_line.split()
		elif input_format == 4:
			formatted_input = (lambda x: [x[0], list(map(int, x[1:]))])(next_line.split())
		elif input_format == 5:
			formatted_input = (lambda x: [x[0], list(map(float, x[1:]))])(next_line.split())
		else:
			formatted_input = [next_line]
		return formatted_input

def log(*args):
	if testing_mode:
		print(*args)

def out(output_line, output_format=0, newline=True):
	global final_output
	formatted_output = ''
	if output_format == 0:
		formatted_output = str(output_line)
	elif output_format == 1:
		formatted_output = ' '.join(map(str, output_line))
	elif output_format == 1:
		formatted_output = '\n'.join(map(str, output_line))
	if testing_mode:
		final_output += formatted_output + '\n' * newline
	else:
		print(formatted_output, end='\n' if newline else '')
test_inputs = ['\n10\n1 1\n.\n1 2\nG.\n2 2\n#B\nG.\n2 3\nG.#\nB#.\n3 3\n#B.\n#..\nGG.\n2 2\n#B\nB.\n4 4\nGGGG\nGGGG\nGGGG\nGGG.\n4 4\nB.GG\n..GG\nGGGG\nGGG.\n4 4\nBGGG\n..GG\nGGGG\nGGG.\n3 4\nG...\n###.\nB...\n\n', '\n1\n4 4\nGGGG\nGGGG\nGGGG\nGGG.\n', '\n$$$\n', '\n$$$\n']
test_outputs = ['\nYes\nYes\nNo\nNo\nYes\nYes\nYes\nYes\nNo\nYes\n\n', '\n$$$\n', '\n$$$\n', '\n$$$\n']
import collections

def getAdj(n, m, x, y):
	adj = []
	if x < m - 1:
		adj.append((x + 1, y))
	if x > 0:
		adj.append((x - 1, y))
	if y < n - 1:
		adj.append((x, y + 1))
	if y > 0:
		adj.append((x, y - 1))
	return adj

def solve():

	def s(n, m, x, y):
		nonlocal k
		if k[y][x] == '*':
			return True
		v = []
		vl = [(x, y)]
		for i in range(n):
			v.append([False] * m)
		q = collections.deque([(x, y)])
		v[y][x] = True
		found = False
		while q:
			f = q.popleft()
			adj = getAdj(n, m, f[0], f[1])
			for (i, j) in adj:
				log(i, j)
				if not v[j][i] and k[j][i] != '#':
					if k[j][i] == '*':
						found = True
					q.append((i, j))
					v[j][i] = True
					vl.append((i, j))
				if found:
					break
		if found:
			for (i, j) in vl:
				k[j][i] = '*'
			return True
		else:
			return False
	for z in range(input(1)[0]):
		(n, m) = input(1)
		k = []
		for i in range(n):
			k.append([x for x in input(0)[0] if x != '\n'])
		k[-1][-1] = '*'
		g = []
		b = []
		for (i, r) in enumerate(k):
			for (j, c) in enumerate(r):
				if c == 'G':
					g.append((j, i))
				elif c == 'B':
					b.append((j, i))
		fail = False
		for (x, y) in b:
			adj = getAdj(n, m, x, y)
			for (xa, ya) in adj:
				if k[ya][xa] == '.' or k[ya][xa] == '*':
					k[ya][xa] = '#'
				elif k[ya][xa] == 'G':
					fail = True
					break
		for i in k:
			log(i)
		log()
		if fail:
			out('No')
		else:
			for (x, y) in g:
				if not s(n, m, x, y):
					out('No')
					break
				for i in k:
					log(i)
				log()
			else:
				out('Yes')
		log()
	return

def run_all(overwrite_testing=False):
	global testing_mode, final_output, test_data
	testing_mode = overwrite_testing and testing_mode
	if testing_mode:
		tests_failed = 0
		for (test_number, (test_in, test_out)) in enumerate(zip(test_inputs, test_outputs)):
			final_output = ''
			if test_in.lstrip()[:3] == '$$$':
				continue
			test_data = iter([i for i in test_in.split('\n') if i])
			print(f'Test Case #{test_number + 1}:')
			print('<' * 20)
			fail = False
			verdict = '\x1b[92m\x1b[1mPASS\x1b[0m'
			try:
				solve()
				final = final_output.rstrip('\n')
				raw_out = iter(map(str, final.split('\n'))) if final else iter(())
			except Exception:
				raw_out = ''
				fail = True
				print('\x1b[95m')
				traceback.print_exc()
				print('\x1b[0m')
			if raw_out:
				if test_out.lstrip()[:3] == '$$$':
					verdict = '\x1b[94m\x1b[1mSKIP\x1b[0m'
					print('\x1b[94m' + '\n'.join(list(raw_out)) + '\x1b[0m')
				else:
					for line_out in [i for i in test_out.split('\n') if i]:
						line_raw = next(raw_out, '% None %')
						if line_raw == line_out.strip():
							print(f'\x1b[92m{line_raw}\x1b[0m')
						else:
							print(f'\x1b[91m{line_raw}\x1b[0m')
							fail = True
					line_raw = next(raw_out, None)
					while line_raw:
						print(f'\x1b[91m{line_raw}\x1b[0m')
						line_raw = next(raw_out, None)
						fail = True
			print('>' * 20)
			if fail:
				verdict = '\x1b[91m\x1b[1mFAIL\x1b[0m'
				tests_failed += 1
			print(verdict + '\n')
		if tests_failed:
			print(f"\x1b[91m\x1b[1m{tests_failed} TEST{('S' if tests_failed > 1 else '')} FAILED!\x1b[0m")
		else:
			print(f'\x1b[92m\x1b[1mALL TESTS PASSED!\x1b[0m')
	else:
		test_data = False
		solve()
run_all(0)


import sys
input = sys.stdin.readline
from collections import deque

def solve(n, m, A):
	Map = [['.'] * m for _ in range(n)]
	Gs = []
	Bs = []
	for (i, a) in enumerate(A):
		for (j, s) in enumerate(a):
			if s == '#':
				Map[i][j] = '#'
			elif s == 'G':
				Gs.append((i, j))
			elif s == 'B':
				Bs.append((i, j))
				Map[i][j] = '#'
	if len(Gs) == 0:
		return 'Yes'
	D = [(1, 0), (-1, 0), (0, 1), (0, -1)]
	for (x, y) in Bs:
		for (dx, dy) in D:
			(to_x, to_y) = (x + dx, y + dy)
			if to_x < 0 or to_x >= n or to_y < 0 or (to_y >= m):
				continue
			Map[to_x][to_y] = '#'
	if Map[n - 1][m - 1] == '#':
		return 'No'
	q = deque()
	q.append((n - 1, m - 1))
	Visited = [[0] * m for _ in range(n)]
	Visited[n - 1][m - 1] = 1
	while q:
		(x, y) = q.popleft()
		for (dx, dy) in D:
			(to_x, to_y) = (x + dx, y + dy)
			if to_x < 0 or to_x >= n or to_y < 0 or (to_y >= m):
				continue
			if Map[to_x][to_y] == '.' and Visited[to_x][to_y] == 0:
				q.append((to_x, to_y))
				Visited[to_x][to_y] = 1
	for (x, y) in Gs:
		if Visited[x][y] == 0:
			return 'No'
	return 'Yes'

def main():
	t = int(input())
	for _ in range(t):
		(n, m) = map(int, input().split())
		A = [list(input().strip()) for _ in range(n)]
		ans = solve(n, m, A)
		sys.stdout.write(ans + '\n')
main()


from sys import stdin, gettrace
from collections import deque
if gettrace():
	inputi = input
else:

	def input():
		return next(stdin)[:-1]

	def inputi():
		return stdin.buffer.readline()

def main():

	def solve():
		(n, m) = map(int, input().split())
		maze = []
		for _ in range(n):
			maze.append(list(input()))
		gcount = 0
		for i in range(n):
			for j in range(m):
				if maze[i][j] == 'B':
					adj = [(i - 1, j), (i, j - 1), (i + 1, j), (i, j + 1)]
					for (z, w) in adj:
						if 0 <= z < n and 0 <= w < m and (maze[z][w] == '.'):
							maze[z][w] = '#'
				elif maze[i][j] == 'G':
					gcount += 1
		visited = [[False] * m for _ in range(n)]
		if maze[n - 1][m - 1] == '#':
			if gcount == 0:
				print('Yes')
			else:
				print('No')
			return
		dq = deque()
		dq.append((n - 1, m - 1))
		visited[n - 1][m - 1] = True
		while dq:
			(x, y) = dq.pop()
			adj = [(x - 1, y), (x, y - 1), (x + 1, y), (x, y + 1)]
			for (z, w) in adj:
				if 0 <= z < n and 0 <= w < m and (not visited[z][w]) and (maze[z][w] != '#'):
					if maze[z][w] == 'G':
						gcount -= 1
					elif maze[z][w] == 'B':
						print('No')
						return
					visited[z][w] = True
					dq.append((z, w))
		if gcount == 0:
			print('Yes')
		else:
			print('No')
	q = int(inputi())
	for _ in range(q):
		solve()
main()


t = int(input())

def nbs(sq, dims):
	(i, j) = sq
	(n, m) = dims
	res = []
	if i - 1 >= 0:
		res.append((i - 1, j))
	if j - 1 >= 0:
		res.append((i, j - 1))
	if i + 1 <= n - 1:
		res.append((i + 1, j))
	if j + 1 <= m - 1:
		res.append((i, j + 1))
	return res

def case():
	[n, m] = list(map(int, input().split()))
	maze = []
	Bs = []
	Gs = []
	for i in range(n):
		maze.append(list(input()))
		for j in range(m):
			sq = maze[i][j]
			if sq == 'B':
				Bs.append((i, j))
			elif sq == 'G':
				Gs.append((i, j))
	if len(Gs) == 0:
		return True
	for (i, j) in Bs:
		nbrs = nbs((i, j), (n, m))
		for nbr in nbrs:
			(inb, jnb) = (nbr[0], nbr[1])
			if maze[inb][jnb] == 'G' or (inb, jnb) == (n - 1, m - 1):
				return False
			elif maze[inb][jnb] != 'B':
				maze[inb][jnb] = '#'
	cc = {(n - 1, m - 1)}
	wave = [(n - 1, m - 1)]
	Gs_in_cc = 0
	while len(wave) > 0:
		new_wave = []
		for sq in wave:
			for (i, j) in nbs(sq, (n, m)):
				if (i, j) not in cc:
					cand = maze[i][j]
					if cand == '.':
						new_wave.append((i, j))
						cc.add((i, j))
					elif cand == 'G':
						new_wave.append((i, j))
						Gs_in_cc += 1
						cc.add((i, j))
		wave = new_wave
	if Gs_in_cc == len(Gs):
		return True
	else:
		return False
for test_case in range(t):
	poss = case()
	if poss:
		print('Yes')
	else:
		print('No')


from collections import defaultdict as dft
import sys
import math

def ml():
	return list(map(int, input().split()))

def mp():
	return map(int, input().split())

def debug(name, val):
	print(name, ':', val)
sys.setrecursionlimit(10 ** 5)

def bfs(x, y, posi, dr, n, m, grid):
	posi[x][y] = 1
	for (i, j) in dr:
		if 0 <= i + x < n and 0 <= j + y < m:
			if grid[i + x][j + y] == '#' or posi[i + x][j + y]:
				continue
			bfs(i + x, j + y, posi, dr, n, m, grid)

def solve():
	(n, m) = map(int, input().split())
	grid = []
	cg = 0
	for i in range(n):
		ls = list(input())
		cg += ls.count('G')
		grid.append(ls)
	if cg == 0:
		return True
	dr = [[1, 0], [0, 1], [-1, 0], [0, -1]]
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 'B':
				for (x, y) in dr:
					if 0 <= i + x < n and 0 <= j + y < m:
						if grid[i + x][j + y] == 'G':
							return False
						if grid[i + x][j + y] == '.':
							grid[i + x][j + y] = '#'
	if grid[n - 1][m - 1] == '#':
		return False
	posi = [[0 for i in range(m)] for j in range(n)]
	bfs(n - 1, m - 1, posi, dr, n, m, grid)
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 'G':
				if posi[i][j] == 0:
					return False
	return True
t = int(input())
for _ in range(t):
	if solve():
		print('Yes')
	else:
		print('No')


import sys
import math
import collections
from sys import stdin, stdout, setrecursionlimit
import bisect as bs
setrecursionlimit(2 ** 20)
M = 10 ** 9 + 7
T = int(stdin.readline())
for _ in range(T):
	(n, m) = list(map(int, stdin.readline().split()))
	g = []
	vis = []
	goods = 0
	for j in range(n):
		g.append([])
		vis.append([False] * m)
		s = stdin.readline().strip('\n')
		for i in range(m):
			if s[i] == '#':
				g[j].append(0)
			if s[i] == 'G':
				g[j].append(1)
				goods += 1
			if s[i] == 'B':
				g[j].append(-1)
			if s[i] == '.':
				g[j].append(2)
	for i in range(n):
		for j in range(m):
			if g[i][j] == -1:
				if i - 1 >= 0 and g[i - 1][j] == 2:
					g[i - 1][j] = 0
				if i + 1 < n and g[i + 1][j] == 2:
					g[i + 1][j] = 0
				if j - 1 >= 0 and g[i][j - 1] == 2:
					g[i][j - 1] = 0
				if j + 1 < m and g[i][j + 1] == 2:
					g[i][j + 1] = 0
	if g[n - 1][m - 1] == 0:
		if goods != 0:
			print('No')
			continue
		else:
			print('Yes')
			continue
	a = [(n - 1, m - 1)]
	vis[n - 1][m - 1] = True
	gvis = 0
	bvis = 0
	while a:
		(x, y) = a.pop()
		if g[x][y] == 1:
			gvis += 1
		if g[x][y] == -1:
			bvis += 1
		if x - 1 >= 0 and g[x - 1][y] != 0 and (not vis[x - 1][y]):
			vis[x - 1][y] = True
			a.append((x - 1, y))
		if x + 1 < n and g[x + 1][y] != 0 and (not vis[x + 1][y]):
			vis[x + 1][y] = True
			a.append((x + 1, y))
		if y - 1 >= 0 and g[x][y - 1] != 0 and (not vis[x][y - 1]):
			vis[x][y - 1] = True
			a.append((x, y - 1))
		if y + 1 < m and g[x][y + 1] != 0 and (not vis[x][y + 1]):
			vis[x][y + 1] = True
			a.append((x, y + 1))
	if gvis == goods and bvis == 0:
		print('Yes')
	else:
		print('No')


from random import randint, choice

def dfs():
	used = set()
	st = [(n - 1, m - 1)]
	ans = 0
	while st:
		now = st.pop()
		if now not in used:
			used.add(now)
			now_st = []
			bol = True
			for ism_i in range(-1, 2):
				for ism_j in range(-1, 2):
					if ism_i == 0 and ism_j != 0 or (ism_i != 0 and ism_j == 0):
						if 0 <= now[0] + ism_i < n and 0 <= now[1] + ism_j < m and ((now[0] + ism_i, now[1] + ism_j) not in used):
							new_now = (now[0] + ism_i, now[1] + ism_j)
							if mass[new_now[0]][new_now[1]] == 'G' or mass[new_now[0]][new_now[1]] == '.':
								now_st.append(new_now)
							elif mass[new_now[0]][new_now[1]] == 'B':
								bol = False
			if bol:
				st += now_st
				if mass[now[0]][now[1]] == 'G':
					ans += 1
	return ans
t = int(input())
for q in range(t):
	(n, m) = map(int, input().split())
	mass = [list(input()) for j in range(n)]
	sch = 0
	for i in range(n):
		for j in range(m):
			if mass[i][j] == 'G':
				sch += 1
	if sch == dfs():
		print('Yes')
	else:
		print('No')


def valid(x, y):
	return 0 <= x < n and 0 <= y < m
dirc = [(1, 0), (0, 1), (0, -1), (-1, 0)]
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	for _ in range(n):
		temp = [el for el in input()]
		arr.append(temp)
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'B':
				for (dx, dy) in dirc:
					(nx, ny) = (dx + i, dy + j)
					if valid(nx, ny) and arr[nx][ny] == '.':
						arr[nx][ny] = '#'
	q = []
	seen = set()
	if arr[-1][-1] == '.':
		q.append((n - 1, m - 1))
		seen.add((n - 1, m - 1))
	while q:
		(x, y) = q.pop()
		for (dx, dy) in dirc:
			(nx, ny) = (dx + x, dy + y)
			if valid(nx, ny) and (nx, ny) not in seen and (arr[nx][ny] != '#'):
				q.append((nx, ny))
				seen.add((nx, ny))
	good = True
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'G' and (i, j) not in seen or (arr[i][j] == 'B' and (i, j) in seen):
				good = False
	if good:
		print('Yes')
	else:
		print('No')


t = int(input())
S = [1, -1, 0, 0]
D = [0, 0, 1, -1]

def good(r, c, n, m):
	return r >= 0 and c >= 0 and (r < n) and (c < m)

def f(matrix, n, m):
	posizioni = list()
	for row in range(n):
		for col in range(m):
			if matrix[row][col] == 'G':
				posizioni.append((row, col))
	visited = set()
	for row in range(n):
		for col in range(m):
			if (row, col) not in visited and matrix[row][col] == 'B':
				stack = [[row, col]]
				while stack:
					(r, c) = stack.pop()
					visited.add((r, c))
					for i in range(4):
						R = r + S[i]
						C = c + D[i]
						if good(R, C, n, m) and (R, C) not in visited:
							visited.add((R, C))
							if matrix[R][C] == 'B':
								stack.append([R, C])
								matrix[R][C] = '#'
							elif matrix[R][C] == 'G':
								return 'No'
							else:
								matrix[R][C] = '#'
	if matrix[n - 1][m - 1] == '#':
		return 'No'
	ok = [[0 for _ in range(m)] for _ in range(n)]
	visited2 = set()
	stack = [[n - 1, m - 1]]
	while stack:
		(r, c) = stack.pop()
		visited2.add((r, c))
		ok[r][c] = 1
		for i in range(4):
			R = r + S[i]
			C = c + D[i]
			if good(R, C, n, m) and (R, C) not in visited2:
				visited2.add((R, C))
				if matrix[R][C] in ['.', 'G']:
					stack.append([R, C])
	for pos in posizioni:
		if ok[pos[0]][pos[1]] == 0:
			return 'No'
	return 'Yes'
for test in range(t):
	[n, m] = list(map(int, input().rstrip().split()))
	matrix = [['.' for _ in range(m)] for _ in range(n)]
	countG = 0
	for row in range(n):
		s = input()
		for col in range(m):
			matrix[row][col] = s[col]
			if matrix[row][col] == 'G':
				countG += 1
	if countG == 0:
		print('Yes')
	else:
		print(f(matrix, n, m))


import sys
from collections import deque as dq
input = sys.stdin.readline

def solve():
	(H, W) = map(int, input().split())
	a = [list(input())[:-1] for _ in range(H)]
	Q = dq([H * W - 1])
	d = [-1, 0, 1, 0]
	g = 0
	for y in range(H):
		for x in range(W):
			g |= a[y][x] == 'G'
			if a[y][x] == 'B':
				for k in range(4):
					u = y + d[k]
					v = x + d[-1 - k]
					if u in range(H) and v in range(W):
						if a[u][v] == 'G':
							print('No')
							return
						if a[u][v] == '.':
							a[u][v] = '#'
	if g and a[-1][-1] == '#':
		print('No')
		return
	table = [0] * (H * W)
	while len(Q):
		p = Q.popleft()
		table[p] = 1
		y = p // W
		x = p % W
		for k in range(4):
			u = y + d[k]
			v = x + d[-1 - k]
			if u in range(H) and v in range(W):
				if table[u * W + v]:
					continue
				if a[u][v] == '#':
					continue
				table[u * W + v] = 1
				Q.append(u * W + v)
	for y in range(H):
		for x in range(W):
			if a[y][x] == 'G':
				if table[y * W + x] == 0:
					print('No')
					return
	print('Yes')
	return
for _ in range(int(input())):
	solve()


def isPoss(i, j, mat, poss, n, m):
	poss[i][j] = 1
	if i - 1 >= 0 and poss[i - 1][j] == -1 and (mat[i - 1][j] != '#') and (mat[i - 1][j] != 'B'):
		isPoss(i - 1, j, mat, poss, n, m)
	if i + 1 < n and poss[i + 1][j] == -1 and (mat[i + 1][j] != '#') and (mat[i + 1][j] != 'B'):
		isPoss(i + 1, j, mat, poss, n, m)
	if j - 1 >= 0 and poss[i][j - 1] == -1 and (mat[i][j - 1] != '#') and (mat[i][j - 1] != 'B'):
		isPoss(i, j - 1, mat, poss, n, m)
	if j + 1 < m and poss[i][j + 1] == -1 and (mat[i][j + 1] != '#') and (mat[i][j + 1] != 'B'):
		isPoss(i, j + 1, mat, poss, n, m)
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	mat = []
	poss = [[-1 for i in range(m)] for i in range(n)]
	poss[n - 1][m - 1] = 1
	bad = []
	good = []
	g = 0
	for i in range(n):
		mat.append(list(input()))
		for j in range(m):
			if mat[i][j] == 'B':
				bad.append([i, j])
			elif mat[i][j] == 'G':
				good.append([i, j])
				g += 1
	isPoss(n - 1, m - 1, mat, poss, n, m)
	flag = 1
	for t in bad:
		i = t[0]
		j = t[1]
		if i - 1 >= 0 and poss[i - 1][j] == 1:
			if mat[i - 1][j] == 'G':
				flag = 0
				break
			mat[i - 1][j] = '#'
		if i + 1 < n and poss[i + 1][j] == 1:
			if mat[i + 1][j] == 'G':
				flag = 0
				break
			mat[i + 1][j] = '#'
		if j - 1 >= 0 and poss[i][j - 1] == 1:
			if mat[i][j - 1] == 'G':
				flag = 0
				break
			mat[i][j - 1] = '#'
		if j + 1 < m and poss[i][j + 1] == 1:
			if mat[i][j + 1] == 'G':
				flag = 0
				break
			mat[i][j + 1] = '#'
	if flag != 0:
		poss1 = [[-1 for i in range(m)] for i in range(n)]
		if mat[n - 1][m - 1] == '#' and g != 0:
			flag = 0
		if flag != 0:
			isPoss(n - 1, m - 1, mat, poss1, n, m)
			for t in good:
				if poss1[t[0]][t[1]] == -1:
					flag = 0
					break
	print('No' if flag == 0 else 'Yes')


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())

	def ck(x, y):
		return x >= 0 and y >= 0 and (x < n) and (y < m)
	maze = [[0] for y in range(n)]
	tx = [0, 0, -1, 1]
	ty = [1, -1, 0, 0]
	Bad = []
	for i in range(n):
		maze[i] = list(input())
	end = False
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'B':
				for k in range(4):
					x = i + tx[k]
					y = j + ty[k]
					if ck(x, y):
						if maze[x][y] == '.':
							maze[x][y] = '#'
						if maze[x][y] == 'G':
							end = True
							break
			if end:
				break
		if end:
			break
	if end:
		print('No')
		continue
	q = []
	vis = [[0 for x in range(m)] for y in range(n)]
	if maze[n - 1][m - 1] != '#':
		vis[n - 1][m - 1] = 1
		q.append([n - 1, m - 1])
	while q:
		tem = q.pop(0)
		x = tem[0]
		y = tem[1]
		for i in range(4):
			if ck(x + tx[i], y + ty[i]):
				if maze[x + tx[i]][y + ty[i]] != '#' and vis[x + tx[i]][y + ty[i]] == 0:
					vis[x + tx[i]][y + ty[i]] = 1
					q.append([x + tx[i], y + ty[i]])
	ok = True
	for i in range(n):
		for y in range(m):
			if maze[i][y] == 'G' and vis[i][y] == 0:
				end = True
				break
		if end:
			break
	if end:
		print('No')
	else:
		print('Yes')


import sys
strings = iter(sys.stdin.read().split())
ints = (int(x) for x in strings)
sys.setrecursionlimit(3000)

def block(m, R, C, esc, r, c):
	if esc[r][c] == 0:
		return 1
	q = [(r, c)]
	h = set([(r, c)])
	while q:
		(r, c) = q.pop()
		if m[r][c] == '.':
			m[r][c] = '#'
		if m[r][c] != '#' and r == R - 1 and (c == C - 1):
			return 0
		if m[r][c] != '#':
			for (r, c) in ((r - 1, c), (r + 1, c), (r, c - 1), (r, c + 1)):
				if 0 <= r < R and 0 <= c < C and ((r, c) not in h):
					q.append((r, c))
					h.add((r, c))
	for (r, c) in h:
		esc[r][c] = 0
	return 1

def reachability(m, R, C):
	esc = [[0 for c in range(C)] for r in range(R)]
	q = [(R - 1, C - 1)]
	while q:
		(r, c) = q.pop()
		esc[r][c] = 1
		if m[r][c] != '#':
			for (r, c) in ((r - 1, c), (r + 1, c), (r, c - 1), (r, c + 1)):
				if 0 <= r < R and 0 <= c < C and (esc[r][c] == 0):
					q.append((r, c))
	return esc

def main():
	ntc = next(ints)
	for tc in range(1, ntc + 1):
		(R, C) = (next(ints) for i in range(2))
		m = [list(next(strings)) for r in range(R)]
		B = [(r, c) for r in range(R) for c in range(C) if m[r][c] == 'B']
		G = [(r, c) for r in range(R) for c in range(C) if m[r][c] == 'G']
		esc = reachability(m, R, C)
		ans = all((esc[r][c] for (r, c) in G))
		if ans:
			ans = all((block(m, R, C, esc, r, c) for (r, c) in B))
		if ans:
			esc = reachability(m, R, C)
			ans = all((esc[r][c] for (r, c) in G))
		print('Yes' if ans else 'No')
	return
main()


def solve():
	(n, m) = map(int, input().split())
	a = [list(input()) for _ in range(n)]

	def bad(i, j):
		if i - 1 >= 0:
			if a[i - 1][j] == 'G':
				return False
			if a[i - 1][j] == '.':
				a[i - 1][j] = '$'
		if j - 1 >= 0:
			if a[i][j - 1] == 'G':
				return False
			if a[i][j - 1] == '.':
				a[i][j - 1] = '$'
		if i + 1 < n:
			if a[i + 1][j] == 'G':
				return False
			if a[i + 1][j] == '.':
				a[i + 1][j] = '$'
		if j + 1 < m:
			if a[i][j + 1] == 'G':
				return False
			if a[i][j + 1] == '.':
				a[i][j + 1] = '$'
		return True
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'B':
				if not bad(i, j):
					print('No')
					return
	q = []
	vis = [[False] * m for _ in range(n)]
	if a[n - 1][m - 1] in 'GB.':
		q.append((n - 1, m - 1))
		vis[n - 1][m - 1] = True
	gc = 0
	while q:
		(i, j) = q.pop(0)
		if a[i][j] == 'G':
			gc += 1
		if a[i][j] == 'B':
			print('No')
			return
		if i - 1 >= 0 and a[i - 1][j] in 'GB.' and (not vis[i - 1][j]):
			q.append((i - 1, j))
			vis[i - 1][j] = True
		if j - 1 >= 0 and a[i][j - 1] in 'GB.' and (not vis[i][j - 1]):
			q.append((i, j - 1))
			vis[i][j - 1] = True
		if i + 1 < n and a[i + 1][j] in 'GB.' and (not vis[i + 1][j]):
			q.append((i + 1, j))
			vis[i + 1][j] = True
		if j + 1 < m and a[i][j + 1] in 'GB.' and (not vis[i][j + 1]):
			q.append((i, j + 1))
			vis[i][j + 1] = True
	rgc = 0
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'G':
				rgc += 1
	if gc != rgc:
		print('No')
	else:
		print('Yes')
t = int(input())
for _ in range(t):
	solve()


import bisect
import sys
import math
input = sys.stdin.readline
from collections import defaultdict

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

def dfs(b, i, j, visited):
	stack = [(i, j)]
	while len(stack) > 0:
		(i, j) = stack.pop()
		visited[i][j] = True
		for (di, dj) in [(i - 1, j), (i, j - 1), (i, j + 1), (i + 1, j)]:
			if di < 0 or di >= len(b) or dj < 0 or (dj >= len(b[di])):
				continue
			if b[di][dj] == '#':
				continue
			if visited[di][dj]:
				continue
			stack.append((di, dj))

def solve2(case):
	[n, m] = inlt()
	b = [list(input().strip()) for i in range(n)]
	gcount = sum((sum((1 if c == 'G' else 0 for c in row)) for row in b))
	bcount = sum((sum((1 if c == 'B' else 0 for c in row)) for row in b))
	if b[-1][-1] == 'B':
		return False
	if gcount == 0:
		return True
	for i in range(n):
		for j in range(m):
			if b[i][j] == 'B':
				for (di, dj) in [(i - 1, j), (i, j - 1), (i, j + 1), (i + 1, j)]:
					if di < 0 or di >= n or dj < 0 or (dj >= m):
						continue
					if b[di][dj] == '.':
						b[di][dj] = '#'
	visited = [[False for _ in range(m)] for _ in range(n)]
	dfs(b, n - 1, m - 1, visited)
	gvis = sum((sum((1 if b[i][j] == 'G' and visited[i][j] else 0 for j in range(m))) for i in range(n)))
	bvis = sum((sum((1 if b[i][j] == 'B' and visited[i][j] else 0 for j in range(m))) for i in range(n)))
	return gvis == gcount and bvis == 0

def solve(case):
	return 'Yes' if solve2(case) else 'No'
if len(sys.argv) > 1 and sys.argv[1].startswith('input'):
	f = open('./' + sys.argv[1], 'r')
	input = f.readline
T = inp()
for i in range(T):
	res = solve(i + 1)
	print(str(res))


def solve(n, m, maze):
	cnt = 0
	steps = [[0, 1], [1, 0], [-1, 0], [0, -1]]
	cross_border = lambda x, y, n, m: x < 0 or y < 0 or x >= n or (y >= m)
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'G':
				cnt += 1
			if maze[i][j] != 'B':
				continue
			for (si, sj) in steps:
				(x, y) = (i + si, j + sj)
				if cross_border(x, y, n, m) or maze[x][y] == 'B':
					continue
				if maze[x][y] == 'G':
					return 'No'
				maze[x][y] = '#'
	bfs = [(n - 1, m - 1)]
	visited = [[False] * m for _ in range(n)]
	while bfs:
		(i, j) = bfs[0]
		bfs.pop(0)
		if visited[i][j] or maze[i][j] == '#':
			continue
		visited[i][j] = True
		if maze[i][j] == 'G':
			cnt -= 1
		for (si, sj) in steps:
			(x, y) = (i + si, j + sj)
			if cross_border(x, y, n, m):
				continue
			bfs.append((x, y))
	if cnt:
		return 'No'
	return 'Yes'

def main():
	inp = lambda : [int(x) for x in input().split()]
	inn = lambda : int(input())
	t = inn()
	for _ in range(t):
		(n, m) = inp()
		maze = []
		for _ in range(n):
			maze.append(list(input()))
		print(solve(n, m, maze))
main()


from sys import stdin
for case in range(int(stdin.readline())):
	(n, m) = [int(x) for x in stdin.readline().split()]
	grid = []
	for x in range(n):
		grid.append(list(stdin.readline().strip()))
	valid = True
	for x in range(n):
		if valid:
			for y in range(m):
				if grid[x][y] == 'B':
					if x > 0:
						if grid[x - 1][y] == 'G':
							valid = False
							break
						if grid[x - 1][y] != 'B':
							grid[x - 1][y] = '#'
					if x < n - 1:
						if grid[x + 1][y] == 'G':
							valid = False
							break
						if grid[x + 1][y] != 'B':
							grid[x + 1][y] = '#'
					if y > 0:
						if grid[x][y - 1] == 'G':
							valid = False
							break
						if grid[x][y - 1] != 'B':
							grid[x][y - 1] = '#'
					if y < m - 1:
						if grid[x][y + 1] == 'G':
							valid = False
							break
						if grid[x][y + 1] != 'B':
							grid[x][y + 1] = '#'
					grid[x][y] = '#'
	visited = set()
	q = []
	if grid[-1][-1] != '#':
		q.append((n - 1, m - 1))
	while q:
		(x, y) = q.pop()
		if not (x, y) in visited:
			visited.add((x, y))
			if x > 0:
				if grid[x - 1][y] != '#':
					q.append((x - 1, y))
			if x < n - 1:
				if grid[x + 1][y] != '#':
					q.append((x + 1, y))
			if y > 0:
				if grid[x][y - 1] != '#':
					q.append((x, y - 1))
			if y < m - 1:
				if grid[x][y + 1] != '#':
					q.append((x, y + 1))
	for x in range(n):
		if valid:
			for y in range(m):
				if grid[x][y] == 'G' and (x, y) not in visited:
					valid = False
					break
	if not valid:
		print('No')
	else:
		print('Yes')


def check(ls, a, b, n, m):
	if a >= 0 and a < n and (b >= 0) and (b < m):
		if ls[a][b] != -1:
			return True
	return False

def dfs(ls, i, j, n, m):
	ls1 = [(i, j)]
	st = set(ls1)
	z1 = [[0 for i in range(m)] for j in range(n)]
	z1[i][j] = 1
	x = [-1, 0, 1, 0]
	y = [0, 1, 0, -1]
	ans = 'NO'
	while len(st) != 0:
		(p, q) = st.pop()
		for k in range(4):
			a = p + x[k]
			b = q + y[k]
			if check(ls, a, b, n, m) and z1[a][b] == 0:
				st.add((a, b))
				z1[a][b] = 1
	return z1
for lo in range(int(input())):
	(n, m) = map(int, input().split())
	ls = [[0 for i in range(m)] for j in range(n)]
	c = 0
	for i in range(n):
		st = input()
		for j in range(m):
			ls[i][j] = st[j]
			if st[j] == 'G':
				c += 1
	if c == 0:
		print('YES')
		continue
	ans = 'YES'
	for i in range(n):
		for j in range(m):
			if ls[i][j] == '#':
				ls[i][j] = -1
			if ls[i][j] == 'B':
				if j - 1 >= 0:
					if ls[i][j - 1] == 'G':
						ans = 'NO'
					if ls[i][j - 1] != 'B':
						ls[i][j - 1] = -1
				if i - 1 >= 0:
					if ls[i - 1][j] == 'G':
						ans = 'NO'
					if ls[i - 1][j] != 'B':
						ls[i - 1][j] = -1
				if i + 1 < n:
					if ls[i + 1][j] == 'G':
						ans = 'NO'
					if ls[i + 1][j] != 'B':
						ls[i + 1][j] = -1
				if j + 1 < m:
					if ls[i][j + 1] == 'G':
						ans = 'NO'
					if ls[i][j + 1] != 'B':
						ls[i][j + 1] = -1
				ls[i][j] = -1
	if ans == 'NO' or ls[n - 1][m - 1] == -1:
		print('NO')
		continue
	ans = 'YES'
	ans1 = dfs(ls, n - 1, m - 1, n, m)
	for i in range(n):
		for j in range(m):
			if ls[i][j] == 'G' and ans1[i][j] == 0:
				ans = 'NO'
				break
		if ans == 'NO':
			break
	print(ans)


from collections import deque
T = int(input())

class Found(Exception):
	pass

def neighbours(M, i, j):
	res = []
	if i > 0:
		res.append((i - 1, j))
	if j > 0:
		res.append((i, j - 1))
	if i + 1 < len(M):
		res.append((i + 1, j))
	if j + 1 < len(M[0]):
		res.append((i, j + 1))
	return res

def bfs(M, i, j):
	visited = [[False] * len(M[0]) for _ in range(len(M))]
	visited[i][j] = True
	Q = deque()
	Q.append((i, j))
	answer = 0
	if M[i][j] == 'G':
		answer += 1
	while Q:
		(eli, elj) = Q.popleft()
		if M[eli][elj] == '#':
			continue
		for (ni, nj) in neighbours(M, eli, elj):
			if M[ni][nj] == '#':
				continue
			if visited[ni][nj]:
				continue
			visited[ni][nj] = True
			Q.append((ni, nj))
			if M[ni][nj] == 'G':
				answer += 1
	return answer
for t in range(T):
	(n, m) = [int(_) for _ in input().split()]
	M = []
	count_G = 0
	has_B = False
	for i in range(n):
		row = [_ for _ in input()]
		count_G += row.count('G')
		if 'B' in row:
			has_B = True
		M.append(row)
	try:
		if not count_G:
			if M[n - 1][m - 1] == 'B':
				print('No')
			else:
				print('Yes')
		else:
			for i in range(len(M)):
				for j in range(len(M[0])):
					if M[i][j] == 'B':
						for (x, y) in neighbours(M, i, j):
							if M[x][y] == '.':
								M[x][y] = '#'
							elif M[x][y] == 'G':
								print('No')
								raise Found()
			accessible_G = bfs(M, n - 1, m - 1)
			if accessible_G == count_G:
				print('Yes')
			else:
				print('No')
	except Found:
		pass


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	layout = tuple((list(input().lower()) for _ in range(n)))
	trapped_greens = ''.join(map(''.join, layout)).count('g')
	all_blues = tuple(((i, j) for i in range(n) for j in range(m) if layout[i][j] == 'b'))
	for (i, j) in all_blues:
		if i:
			layout[i - 1][j] = '#'
		if j:
			layout[i][j - 1] = '#'
		if i + 1 < n:
			layout[i + 1][j] = '#'
		if j + 1 < m:
			layout[i][j + 1] = '#'
	stack = [(n - 1, m - 1)]
	while stack:
		(i, j) = stack.pop()
		if layout[i][j] != '#':
			if layout[i][j] == 'g':
				trapped_greens -= 1
			layout[i][j] = '#'
			if i:
				stack.append((i - 1, j))
			if j:
				stack.append((i, j - 1))
			if i + 1 < n:
				stack.append((i + 1, j))
			if j + 1 < m:
				stack.append((i, j + 1))
	if trapped_greens:
		print('No')
	else:
		print('Yes')


import sys, math
import io, os
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write(' '.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
mod = int(1000000000.0) + 7

def main():
	for t in range(int(data())):
		(n, m) = mdata()
		mat = []
		dp = [[0] * m for i in range(n)]
		steps = [(0, 1), (0, -1), (1, 0), (-1, 0)]
		for i in range(n):
			mat.append(data())
		for i in range(n):
			for j in range(m):
				if mat[i][j] == 'B':
					for (a, b) in steps:
						if 0 <= i + a < n and 0 <= j + b < m:
							dp[i + a][j + b] = -1
					dp[i][j] = -1
				if mat[i][j] == '#':
					dp[i][j] = -1
		s = []
		if dp[-1][-1] != -1:
			dp[-1][-1] = 1
			s = [[n - 1, m - 1]]
		while s:
			(i, j) = s.pop()
			for (a, b) in steps:
				if 0 <= i + a < n and 0 <= j + b < m:
					if dp[i + a][j + b] == 0:
						dp[i + a][j + b] = 1
						s.append([i + a, j + b])
		flag = True
		for i in range(n - 1, -1, -1):
			for j in range(m - 1, -1, -1):
				if mat[i][j] == 'G' and dp[i][j] != 1:
					flag = False
					break
			if flag == False:
				break
		if flag == False:
			out('No')
		else:
			out('Yes')
main()


def f():
	return list(map(int, input().split()))

def sol():
	(a, b) = f()
	m = []
	for _ in range(a):
		m.append(list(input()))
	g = 0
	go = [[1, 0], [0, 1], [-1, 0], [0, -1]]
	for i in range(a):
		for j in range(b):
			x = m[i][j]
			if x == 'B':
				for (p, q) in go:
					p += i
					q += j
					if 0 <= p < a and 0 <= q < b:
						if m[p][q] == 'G':
							print('No')
							return
						if m[p][q] == '.':
							m[p][q] = '#'
			if x == 'G':
				g += 1
	if g == 0:
		print('Yes')
		return

	def dfs(p, q):
		nonlocal g
		stack = [[p, q]]
		while len(stack) != 0:
			(p, q) = stack.pop()
			if 0 <= p < a and 0 <= q < b:
				x = m[p][q]
				if x == '#':
					continue
				if x == 'G':
					g -= 1
				m[p][q] = '#'
				for (i, j) in go:
					stack.append((i + p, j + q))
	dfs(a - 1, b - 1)
	if g == 0:
		print('Yes')
	else:
		print('No')
for _ in range(int(input())):
	sol()


def yn(arr, n, m):
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'B':
				if j - 1 >= 0 and arr[i][j - 1] != 'G' and (arr[i][j - 1] != 'B'):
					arr[i][j - 1] = '#'
				if j + 1 < m and arr[i][j + 1] != 'G' and (arr[i][j + 1] != 'B'):
					arr[i][j + 1] = '#'
				if i - 1 >= 0 and arr[i - 1][j] != 'G' and (arr[i - 1][j] != 'B'):
					arr[i - 1][j] = '#'
				if i + 1 < n and arr[i + 1][j] != 'G' and (arr[i + 1][j] != 'B'):
					arr[i + 1][j] = '#'
				if j - 1 >= 0 and arr[i][j - 1] == 'G':
					return 'No'
				if j + 1 < m and arr[i][j + 1] == 'G':
					return 'No'
				if i - 1 >= 0 and arr[i - 1][j] == 'G':
					return 'No'
				if i + 1 < n and arr[i + 1][j] == 'G':
					return 'No'
	return arr
for _ in range(int(input())):
	vis = [[False] * 62 for i in range(62)]
	(n, m) = map(int, input().split())
	arr = []
	ng = 0
	gc = 0
	for i in range(n):
		s = input()
		l = []
		for j in s:
			if j == 'G':
				ng += 1
			l.append(j)
		arr.append(l)
	arr2 = yn(arr, n, m)
	if arr2 == 'No':
		print('No')
	else:
		tags = [[False] * m for _ in range(n)]
		todo = [(n - 1, m - 1)]
		while len(todo) > 0:
			newtodo = []
			for (a, b) in todo:
				if tags[a][b] or arr2[a][b] == '#':
					continue
				tags[a][b] = True
				if a > 0:
					newtodo.append((a - 1, b))
				if b > 0:
					newtodo.append((a, b - 1))
				if a < n - 1:
					newtodo.append((a + 1, b))
				if b < m - 1:
					newtodo.append((a, b + 1))
			todo = newtodo
		for i in range(n):
			for j in range(m):
				if tags[i][j] == True and arr2[i][j] == 'G':
					gc += 1
		if ng == gc:
			print('Yes')
		else:
			print('No')


from collections import defaultdict
T = int(input())
for t in range(T):
	(n, m) = [int(i) for i in input().split()]
	A = [list(input()) for i in range(n)]
	for i in range(n):
		for j in range(m):
			if A[i][j] == 'B':
				if i >= 1 and A[i - 1][j] == '.':
					A[i - 1][j] = '#'
				if j >= 1 and A[i][j - 1] == '.':
					A[i][j - 1] = '#'
				if i < n - 1 and A[i + 1][j] == '.':
					A[i + 1][j] = '#'
				if j < m - 1 and A[i][j + 1] == '.':
					A[i][j + 1] = '#'
	G = defaultdict(set)
	B_set = set()
	G_set = set()
	visited = dict()
	for i in range(n):
		for j in range(m):
			visited[i, j] = False
			if A[i][j] == 'B':
				B_set.add((i, j))
			elif A[i][j] == 'G':
				G_set.add((i, j))
			if A[i][j] != '#':
				if i < n - 1 and A[i + 1][j] != '#':
					G[i, j].add((i + 1, j))
					G[i + 1, j].add((i, j))
				if j < m - 1 and A[i][j + 1] != '#':
					G[i, j].add((i, j + 1))
					G[i, j + 1].add((i, j))
	if A[-1][-1] == '#':
		if len(G_set) > 0:
			print('No')
		else:
			print('Yes')
		continue
	Q = [(n - 1, m - 1)]
	visited[n - 1, m - 1] = True
	exit_flag = False
	visited_good = set()
	while Q and (not exit_flag):
		u = Q.pop()
		for w in G[u]:
			if not visited[w]:
				Q.append(w)
				visited[w] = True
				if w in B_set:
					exit_flag = True
					print('No')
					break
				if w in G_set:
					visited_good.add(w)
	if not exit_flag:
		if len(G_set.difference(visited_good)) > 0:
			print('No')
		else:
			print('Yes')


from collections import deque
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	mat = []
	g = 0
	b = 0
	gl = []
	bl = []
	par = {}
	for j in range(n):
		s = input()
		ll = []
		for i in range(m):
			if s[i] == '#':
				ll.append(float('inf'))
			if s[i] == 'G':
				ll.append(1)
				g += 1
				gl.append((j, i))
			if s[i] == 'B':
				ll.append(-1)
				b += 1
				bl.append((j, i))
			if s[i] == '.':
				ll.append(0)
		mat.append(ll)
	if mat[n - 1][m - 1] == float('inf'):
		print('No')
		continue
	q = deque([(n - 1, m - 1)])
	vis = [[False] * m for _ in range(n)]
	vis[n - 1][m - 1] = True
	while q:
		rmv = q.popleft()
		for dx in range(-1, 2):
			for dy in range(-1, 2):
				if abs(dx) + abs(dy) == 1:
					(ni, nj) = (rmv[0] + dx, rmv[1] + dy)
					if ni >= 0 and nj >= 0 and (ni < n) and (nj < m) and (not vis[ni][nj]) and (mat[ni][nj] != float('inf')):
						vis[ni][nj] = True
						par[ni, nj] = (rmv[0], rmv[1])
						q.append((ni, nj))
	allgs = True
	for i in gl:
		allgs = allgs and vis[i[0]][i[1]]
	if allgs and b == 0 or g == 0:
		print('Yes')
		continue
	if not allgs:
		print('No')
		continue
	vis = [[False] * m for _ in range(n)]
	for p in bl:
		q.append(p)
		vis[p[0]][p[1]] = True
	ll = [(-1, 0), (0, -1), (1, 0), (0, 1)]
	while q:
		rmv = q.popleft()
		possible = []
		f = False
		for i in ll:
			(ni, nj) = (rmv[0] + i[0], rmv[1] + i[1])
			if ni >= 0 and nj >= 0 and (ni < n) and (nj < m) and (not vis[ni][nj]) and (mat[ni][nj] != float('inf')):
				possible.append((ni, nj))
		for i in possible:
			vis[i[0]][i[1]] = True
			if mat[i[0]][i[1]] == 0:
				mat[i[0]][i[1]] = float('inf')
			else:
				q.append(i)
	q = deque([(n - 1, m - 1)])
	vis = [[False] * m for _ in range(n)]
	vis[n - 1][m - 1] = True
	while q:
		rmv = q.popleft()
		for dx in range(-1, 2):
			for dy in range(-1, 2):
				if abs(dx) + abs(dy) == 1:
					(ni, nj) = (rmv[0] + dx, rmv[1] + dy)
					if ni >= 0 and nj >= 0 and (ni < n) and (nj < m) and (not vis[ni][nj]) and (mat[ni][nj] != float('inf')):
						vis[ni][nj] = True
						par[ni, nj] = (rmv[0], rmv[1])
						q.append((ni, nj))
	allgs = True
	for i in gl:
		allgs = allgs and vis[i[0]][i[1]]
	allbs = False
	for i in bl:
		allbs = allbs or vis[i[0]][i[1]]
	if allgs and (not allbs):
		print('Yes')
	else:
		print('No')


import bisect
import heapq
import math
import collections
import sys
import copy
from functools import reduce
import decimal
from io import BytesIO, IOBase
import os
sys.setrecursionlimit(10 ** 9)
decimal.getcontext().rounding = decimal.ROUND_HALF_UP
graphDict = collections.defaultdict
queue = collections.deque

class Graphs:

	def __init__(self):
		self.graph = graphDict(list)

	def add_edge(self, u, v):
		self.graph[u].append(v)
		self.graph[v].append(u)

	def dfs_utility(self, nodes, visited_nodes):
		visited_nodes.add(nodes)
		print(nodes, end='')
		for neighbour in self.graph[nodes]:
			if neighbour not in visited_nodes:
				self.dfs_utility(neighbour, visited_nodes)

	def dfs(self, node):
		Visited = set()
		self.dfs_utility(node, Visited)

	def bfs(self, node):
		visited = set()
		if node not in visited:
			queue.append(node)
			visited.add(node)
		while queue:
			parent = queue.popleft()
			print(parent)
			for item in self.graph[parent]:
				if item not in visited:
					queue.append(item)
					visited.add(item)

class Tree:

	def __init__(self, data):
		self.data = data
		self.left = None
		self.right = None

def inorder(node):
	if node:
		inorder(node.left)
		print(node.data)
		inorder(node.right)

def leaf_node_sum(root):
	if root is None:
		return 0
	if root.left is None and root.right is None:
		return root.data
	return leaf_node_sum(root.left) + leaf_node_sum(root.right)

def hight(root):
	if root is None:
		return -1
	if root.left is None and root.right is None:
		return 0
	return max(hight(root.left), hight(root.right)) + 1

def rounding(n):
	return int(decimal.Decimal(f'{n}').to_integral_value())

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))

def inp():
	return sys.stdin.readline().strip()

def map_inp(v_type):
	return map(v_type, inp().split())

def list_inp(v_type):
	return list(map_inp(v_type))

def flood_fill(r, c, color):
	visit = [(r, c)]
	while visit:
		(rr, cc) = visit.pop()
		if rr < 0 or rr > n - 1 or cc < 0 or (cc > m - 1) or (arr[rr][cc] == '#') or (arr[rr][cc] == 'G') or visited[rr][cc]:
			continue
		if arr[rr][cc] == '.':
			arr[rr][cc] = '#'
			continue
		else:
			visited[rr][cc] = True
			visit.append((rr + 1, cc))
			visit.append((rr - 1, cc))
			visit.append((rr, cc + 1))
			visit.append((rr, cc - 1))

def bfs(r, c):
	global count
	visit = queue([(r, c)])
	while visit:
		(rr, cc) = visit.popleft()
		if rr < 0 or rr > n - 1 or cc < 0 or (cc > m - 1) or (arr[rr][cc] == '#'):
			continue
		if arr[rr][cc] == 'B':
			count = float('inf')
			break
		if visited[rr][cc]:
			continue
		if arr[rr][cc] == 'G':
			count -= 1
		visited[rr][cc] = True
		visit.append((rr + 1, cc))
		visit.append((rr - 1, cc))
		visit.append((rr, cc + 1))
		visit.append((rr, cc - 1))
for _ in range(int(inp())):
	(n, m) = map_inp(int)
	arr = []
	for i in range(n):
		arr.append(list(inp()))
	visited = [[False for col in range(m)] for row in range(n)]
	count = 0
	for i in range(n):
		for j in range(m):
			if not visited[i][j] and arr[i][j] == 'B':
				flood_fill(i, j, arr[i][j])
			if arr[i][j] == 'G':
				count += 1
	bfs(n - 1, m - 1)
	if count == 0:
		print('YES')
	else:
		print('NO')


from __future__ import division, print_function
import os
import sys, math
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def main():
	Test = int(input())
	while Test:
		Test -= 1
		(n, m) = map(int, input().split())
		mat = []
		vis = []
		for i in range(n):
			tmp = list(input())
			vis.append([False] * m)
			mat.append(tmp)
		ans = True
		dirs = [[1, 0], [-1, 0], [0, 1], [0, -1]]

		def check(i, j):
			return i >= 0 and j >= 0 and (i < n) and (j < m)
		for i in range(n):
			for j in range(m):
				if mat[i][j] == 'B':
					for di in dirs:
						x = i + di[0]
						y = j + di[1]
						if check(x, y) and mat[x][y] == '.':
							mat[x][y] = '#'
		from collections import deque
		q = deque()
		if mat[n - 1][m - 1] == '.':
			q.append((n - 1, m - 1))
			vis[n - 1][m - 1] = True
		while len(q):
			p = q.popleft()
			for di in dirs:
				x = p[0] + di[0]
				y = p[1] + di[1]
				if check(x, y) and (not vis[x][y]) and (mat[x][y] != '#'):
					q.append((x, y))
					vis[x][y] = True
		for i in range(n):
			for j in range(m):
				if mat[i][j] == 'G' and (not vis[i][j]):
					ans = False
				elif mat[i][j] == 'B' and vis[i][j]:
					ans = False
		print('yes' if ans else 'no')
	return None
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


from collections import deque
grid = []
(n, m) = (0, 0)
dx = [1, -1, 0, 0]
dy = [0, 0, 1, -1]
vis = []

def data_input():
	global grid, n, m
	(n, m) = map(int, input().split())
	grid = [['#' for _ in range(m + 5)] for __ in range(n + 5)]
	for i in range(1, n + 1):
		grid[i] = ['#'] + list(input()) + ['#']

def check_adj():
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if grid[i][j] == 'B':
				for k in range(4):
					if grid[i + dx[k]][j + dy[k]] == 'G':
						return True
	return False

def surround():
	global grid
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if grid[i][j] == 'B':
				for k in range(4):
					if grid[i + dx[k]][j + dy[k]] == '.':
						grid[i + dx[k]][j + dy[k]] = '#'

def bfs():
	global vis
	vis = [[0 for _ in range(m + 5)] for __ in range(n + 5)]
	q = deque()
	if grid[n][m] != '#':
		q.append((n, m))
		vis[n][m] = 1
	while q:
		now = q.popleft()
		for k in range(4):
			n_x = now[0] + dx[k]
			n_y = now[1] + dy[k]
			if grid[n_x][n_y] != '#' and (not vis[n_x][n_y]):
				vis[n_x][n_y] = 1
				q.append((n_x, n_y))

def check():
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if grid[i][j] == 'G' and (not vis[i][j]):
				return False
	return True

def solve():
	data_input()
	if check_adj():
		print('No')
		return
	surround()
	bfs()
	print(['No', 'Yes'][check()])
t = int(input())
for _ in range(t):
	solve()


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	k = [[c for c in input()] for _ in range(n)]
	d = [[False for _ in range(m)] for _ in range(n)]

	def checkOne():
		for i in range(n):
			for j in range(m):
				if k[i][j] == 'B':
					if i > 0:
						if k[i - 1][j] == 'G':
							return False
						if k[i - 1][j] == '.':
							k[i - 1][j] = '#'
					if j > 0:
						if k[i][j - 1] == 'G':
							return False
						if k[i][j - 1] == '.':
							k[i][j - 1] = '#'
					if i < n - 1:
						if k[i + 1][j] == 'G':
							return False
						if k[i + 1][j] == '.':
							k[i + 1][j] = '#'
					if j < m - 1:
						if k[i][j + 1] == 'G':
							return False
						if k[i][j + 1] == '.':
							k[i][j + 1] = '#'
		h = [[k[i][j] != '#' for j in range(m)] for i in range(n)]
		st = []
		if k[n - 1][m - 1] != '#':
			d[n - 1][m - 1] = True
			st.append([n - 1, m - 1])
		cur = 0
		while cur < len(st):
			(i, j) = st[cur]
			cur += 1
			if i > 0 and (not d[i - 1][j]) and h[i - 1][j]:
				d[i - 1][j] = True
				st.append([i - 1, j])
			if i < n - 1 and (not d[i + 1][j]) and h[i + 1][j]:
				d[i + 1][j] = True
				st.append([i + 1, j])
			if j > 0 and (not d[i][j - 1]) and h[i][j - 1]:
				d[i][j - 1] = True
				st.append([i, j - 1])
			if j < m - 1 and (not d[i][j + 1]) and h[i][j + 1]:
				d[i][j + 1] = True
				st.append([i, j + 1])
		for i in range(n):
			for j in range(m):
				if k[i][j] == 'G':
					if not d[i][j]:
						return False
		return True
	print('Yes' if checkOne() else 'No')


dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]

def solve(n, m, maze):
	total_good_count = 0
	for x in range(1, n + 1):
		for y in range(1, m + 1):
			if maze[x][y] == 'B':
				for k in range(4):
					(nx, ny) = (x + dx[k], y + dy[k])
					if maze[nx][ny] == 'G':
						return False
					elif maze[nx][ny] == '.':
						maze[nx][ny] = '#'
			elif maze[x][y] == 'G':
				total_good_count += 1
	visited = [[False] * (m + 2) for _ in range(n + 1)]
	stack = [(n, m)] if maze[n][m] == '.' else []
	visited[n][m] = True
	escapable_good_count = 0
	while stack:
		(x, y) = stack.pop()
		if maze[x][y] == 'G':
			escapable_good_count += 1
		for k in range(4):
			(nx, ny) = (x + dx[k], y + dy[k])
			if (maze[nx][ny] == '.' or maze[nx][ny] == 'G') and (not visited[nx][ny]):
				visited[nx][ny] = True
				stack.append((nx, ny))
	return escapable_good_count == total_good_count
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	maze = [['#'] * (m + 2)]
	for _ in range(n):
		row = input()
		maze.append(['#'] + list(row) + ['#'])
	maze.append(['#'] * (m + 2))
	r = solve(n, m, maze)
	print('Yes' if r else 'No')


from sys import stdin, stdout
from collections import deque

def main():
	for t in range(int(stdin.readline())):
		(n, m) = map(int, stdin.readline().split())
		a = []
		g = []
		for i in range(n):
			a.append(list(stdin.readline().strip()))
		for i in range(n):
			for j in range(m):
				if a[i][j] == 'B':
					if i != 0:
						if a[i - 1][j] == '.':
							a[i - 1][j] = '#'
					if i != n - 1:
						if a[i + 1][j] == '.':
							a[i + 1][j] = '#'
					if j != 0:
						if a[i][j - 1] == '.':
							a[i][j - 1] = '#'
					if j != m - 1:
						if a[i][j + 1] == '.':
							a[i][j + 1] = '#'
				elif a[i][j] == 'G':
					g.append((i, j))
		z = len(g)
		if z == n * m - 1 or z == 0:
			stdout.write('Yes\n')
			continue
		path = set()
		ans = 'No'
		for i in g:
			ans = 'No'
			visited = set()
			visited.add(i)
			q = deque()
			q.appendleft(i)
			while q:
				b = q.pop()
				if b not in path:
					path.add(b)
				else:
					ans = 'Yes'
					break
				u = b[0]
				v = b[1]
				if u == n - 1 and v == m - 1:
					ans = 'Yes'
					break
				if u != 0:
					if (u - 1, v) not in visited:
						if a[u - 1][v] == '.' or a[u - 1][v] == 'G':
							q.appendleft((u - 1, v))
							visited.add((u - 1, v))
						elif a[u - 1][v] == 'B':
							break
				if u != n - 1:
					if (u + 1, v) not in visited:
						if a[u + 1][v] == '.' or a[u + 1][v] == 'G':
							q.appendleft((u + 1, v))
							visited.add((u + 1, v))
						elif a[u + 1][v] == 'B':
							break
				if v != 0:
					if (u, v - 1) not in visited:
						if a[u][v - 1] == '.' or a[u][v - 1] == 'G':
							q.appendleft((u, v - 1))
							visited.add((u, v - 1))
						elif a[u][v - 1] == 'B':
							break
				if v != m - 1:
					if (u, v + 1) not in visited:
						if a[u][v + 1] == '.' or a[u][v + 1] == 'G':
							q.appendleft((u, v + 1))
							visited.add((u, v + 1))
						elif a[u][v + 1] == 'B':
							break
			if ans != 'Yes':
				break
		stdout.write(ans + '\n')
main()


import io
import os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline

def get_str():
	return input().decode().strip()

def rint():
	return map(int, input().split())

def oint():
	return int(input())

def block_bads():
	for r in range(n):
		for c in range(m):
			if mat[r][c] == 'B':
				if not block_bad(r, c):
					return False
	return True

def block_bad(r, c):
	for (rr, cc) in iter_edge(r, c):
		if rr == n - 1 and cc == m - 1:
			return False
		v = mat[rr][cc]
		if v == '.':
			mat[rr][cc] = '#'
		elif v == 'G':
			return False
	return True

def iter_edge(r, c):
	edge = []
	if r - 1 >= 0:
		edge.append([r - 1, c])
	if r + 1 < n:
		edge.append([r + 1, c])
	if c - 1 >= 0:
		edge.append([r, c - 1])
	if c + 1 < m:
		edge.append([r, c + 1])
	return iter(edge)

def dfs_good(r, c):
	cnt = 0
	if mat[r][c] == 'G':
		cnt = 1
	mat[r][c] = 'v'
	for (rr, cc) in iter_edge(r, c):
		v = mat[rr][cc]
		if v == '#' or v == 'v':
			continue
		cnt += dfs_good(rr, cc)
	return cnt

def count_good():
	cnt = 0
	for i in range(n):
		cnt += mat[i].count('G')
	return cnt
t = oint()
for _ in range(t):
	(n, m) = rint()
	mat = []
	for i in range(n):
		mat.append(list(get_str()))
	gc = count_good()
	if not block_bads():
		if gc == 0:
			print('Yes')
		else:
			print('No')
	elif gc == dfs_good(n - 1, m - 1):
		print('Yes')
	else:
		print('No')


d = [(-1, 0), (1, 0), (0, -1), (0, 1)]

def dfs(i, j, a):
	if a[i][j] == '#':
		return None
	v[i][j] = 1
	for (dx, dy) in d:
		x = i + dx
		y = j + dy
		if x >= 0 and x < n and (y >= 0) and (y < m) and (v[x][y] == 0):
			dfs(x, y, a)
T = int(input())
for _ in range(T):
	(n, m) = list(map(int, input().split()))
	a = [list(input()) for _ in range(n)]
	g = 0
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'G':
				g += 1
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'B':
				for (dx, dy) in d:
					x = i + dx
					y = j + dy
					if x >= 0 and x < n and (y >= 0) and (y < m) and (a[x][y] == '.'):
						a[x][y] = '#'
	v = [[0 for _ in range(m)] for _ in range(n)]
	dfs(n - 1, m - 1, a)
	(vg, vb) = (0, 0)
	for i in range(n):
		for j in range(m):
			if v[i][j]:
				if a[i][j] == 'G':
					vg += 1
				if a[i][j] == 'B':
					vb += 1
	ans = 'Yes' if g == vg and vb == 0 else 'No'
	print(ans)


def isValid(i, j, n, m, table, visited):
	if i >= 0 and j >= 0 and (i < n) and (j < m) and (table[i][j] != '#') and (visited[i][j] == 0):
		return True
	else:
		return False
t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	table = []
	for i in range(n):
		arr = list(input())
		table.append(arr)
	for i in range(n):
		for j in range(m):
			if table[i][j] == 'B':
				if i + 1 < n and table[i + 1][j] == '.':
					table[i + 1][j] = '#'
				if i - 1 >= 0 and table[i - 1][j] == '.':
					table[i - 1][j] = '#'
				if j + 1 < m and table[i][j + 1] == '.':
					table[i][j + 1] = '#'
				if j - 1 >= 0 and table[i][j - 1] == '.':
					table[i][j - 1] = '#'
	visited = []
	for i in range(n):
		visited.append([0] * m)
	q = []
	q.append([n - 1, m - 1])
	visited[n - 1][m - 1] = 1
	while len(q) != 0:
		front = q.pop(0)
		(i, j) = front
		if isValid(i - 1, j, n, m, table, visited):
			q.append([i - 1, j])
			visited[i - 1][j] = 1
		if isValid(i + 1, j, n, m, table, visited):
			q.append([i + 1, j])
			visited[i + 1][j] = 1
		if isValid(i, j - 1, n, m, table, visited):
			q.append([i, j - 1])
			visited[i][j - 1] = 1
		if isValid(i, j + 1, n, m, table, visited):
			q.append([i, j + 1])
			visited[i][j + 1] = 1
	flag = True
	if table[n - 1][m - 1] != '#':
		for i in range(n):
			for j in range(m):
				if table[i][j] == 'G' and visited[i][j] == 0:
					flag = False
					break
				if table[i][j] == 'B' and visited[i][j] == 1:
					flag = False
					break
			if flag == False:
				break
	else:
		for i in range(n):
			for j in range(m):
				if table[i][j] == 'G':
					flag = False
					break
			if flag == False:
				break
	if flag:
		print('Yes')
	else:
		print('No')


import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
inin = lambda : int(input())
inar = lambda : list(map(int, input().split()))
inst = lambda : input().decode().rstrip('\n\r')
from types import GeneratorType

def recursive(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
(n, m) = (0, 0)
maze = []
dx = [-1, 1, 0, 0]
dy = [0, 0, -1, 1]

@recursive
def dfs(i, j, visited):
	visited[i][j] = True
	for delta in range(4):
		x = j + dx[delta]
		y = i + dy[delta]
		if x >= 0 and y >= 0 and (x < m) and (y < n) and (visited[y][x] == False):
			if maze[y][x] == '.' or maze[y][x] == 'G':
				yield dfs(y, x, visited)
	yield
Gloc = []
Testcase = inin()
for _ in range(Testcase):
	Gloc = []
	(n, m) = inar()
	maze = ['' for i in range(n)]
	for i in range(n):
		maze[i] = list(inst())
	pasapasi = False
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'G':
				Gloc.append((i, j))
			if maze[i][j] == 'B':
				for delta in range(4):
					x = j + dx[delta]
					y = i + dy[delta]
					if x >= 0 and y >= 0 and (x < m) and (y < n):
						if maze[y][x] == 'G':
							pasapasi = True
							break
						if maze[y][x] == '.':
							maze[y][x] = '#'
	if pasapasi:
		print('No')
	elif maze[n - 1][m - 1] == '#':
		if Gloc == []:
			print('Yes')
		else:
			print('No')
	else:
		visited = [[False for j in range(m)] for i in range(n)]
		dfs(n - 1, m - 1, visited)
		cond = True
		for (i, j) in Gloc:
			cond = cond and visited[i][j]
		if cond:
			print('Yes')
		else:
			print('No')


t = int(input())
for k in range(t):
	(n, m) = (int(var) for var in input().split())
	maze = []
	for _ in range(n):
		maze.append([var for var in input()])
	(goodBoys, flag, temp) = (0, True, ('B', 'G'))
	for row in range(n):
		if flag is False:
			break
		for col in range(m):
			if maze[row][col] == 'B':
				if row - 1 >= 0:
					if maze[row - 1][col] not in temp:
						maze[row - 1][col] = '#'
					elif maze[row - 1][col] == 'G':
						flag = False
						break
				if row + 1 < n:
					if maze[row + 1][col] not in temp:
						maze[row + 1][col] = '#'
					elif maze[row + 1][col] == 'G':
						flag = False
						break
				if col + 1 < m:
					if maze[row][col + 1] not in temp:
						maze[row][col + 1] = '#'
					elif maze[row][col + 1] == 'G':
						flag = False
						break
				if col - 1 >= 0:
					if maze[row][col - 1] not in temp:
						maze[row][col - 1] = '#'
					elif maze[row][col - 1] == 'G':
						flag = False
						break
			elif maze[row][col] == 'G':
				goodBoys += 1
	if goodBoys == 0 and flag is True:
		print('Yes')
	elif flag is False or maze[n - 1][m - 1] != '.':
		print('No')
	else:
		stack = [(n - 1, m - 1)]
		visited = {(n - 1, m - 1): 1}
		while len(stack) != 0 and goodBoys != 0:
			(row, col) = stack.pop()
			if row - 1 >= 0 and (row - 1, col) not in visited:
				visited[row - 1, col] = 1
				if maze[row - 1][col] == 'G':
					goodBoys -= 1
					stack.append((row - 1, col))
				elif maze[row - 1][col] == '.':
					stack.append((row - 1, col))
			if row + 1 < n and (row + 1, col) not in visited:
				visited[row + 1, col] = 1
				if maze[row + 1][col] == 'G':
					goodBoys -= 1
					stack.append((row + 1, col))
				elif maze[row + 1][col] == '.':
					stack.append((row + 1, col))
			if col - 1 >= 0 and (row, col - 1) not in visited:
				visited[row, col - 1] = 1
				if maze[row][col - 1] == 'G':
					goodBoys -= 1
					stack.append((row, col - 1))
				elif maze[row][col - 1] == '.':
					stack.append((row, col - 1))
			if col + 1 < m and (row, col + 1) not in visited:
				visited[row, col + 1] = 1
				if maze[row][col + 1] == 'G':
					goodBoys -= 1
					stack.append((row, col + 1))
				elif maze[row][col + 1] == '.':
					stack.append((row, col + 1))
		print('Yes' if goodBoys == 0 else 'No')


import sys
input = sys.stdin.readline
from collections import deque
for T in range(int(input())):
	(n, m) = list(map(int, input().split()))
	arr = []
	for i in range(n):
		arr.append(list(input().strip()))
	ans = 1
	cnt = 0
	x = 1
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'B':
				if i + 1 < n and arr[i + 1][j] == 'G':
					ans = -1
					break
				elif i + 1 < n and arr[i + 1][j] == '.':
					arr[i + 1][j] = '#'
				if j + 1 < m and arr[i][j + 1] == 'G':
					ans = -1
					break
				elif j + 1 < m and arr[i][j + 1] == '.':
					arr[i][j + 1] = '#'
				if j - 1 >= 0 and arr[i][j - 1] == 'G':
					ans = -1
					break
				elif j - 1 >= 0 and arr[i][j - 1] == '.':
					arr[i][j - 1] = '#'
				if i - 1 >= 0 and arr[i - 1][j] == 'G':
					ans = -1
					break
				elif i - 1 >= 0 and arr[i - 1][j] == '.':
					arr[i - 1][j] = '#'
			elif arr[i][j] == 'G':
				cnt += 1
	if ans == -1:
		print('NO')
	elif cnt == 0:
		print('YES')
	else:
		count = 0
		dq = deque()
		dq.append((n - 1, m - 1))
		visit = [[False] * m for i in range(n)]
		while dq:
			(x, y) = dq.popleft()
			visit[x][y] = True
			if arr[x][y] != '#':
				if arr[x][y] == 'G':
					count += 1
				if x - 1 >= 0 and visit[x - 1][y] == False:
					dq.append((x - 1, y))
					visit[x - 1][y] = True
				if y - 1 >= 0 and visit[x][y - 1] == False:
					dq.append((x, y - 1))
					visit[x][y - 1] = True
				if x + 1 < n and visit[x + 1][y] == False:
					dq.append((x + 1, y))
					visit[x + 1][y] = True
				if y + 1 < m and visit[x][y + 1] == False:
					dq.append((x, y + 1))
					visit[x][y + 1] = True
		if count == cnt:
			print('YES')
		else:
			print('NO')


import sys
input = sys.stdin.readline
sys.setrecursionlimit = 10 ** 4

def dfs(visited, curr, maze, n, m):
	visited.add(curr)
	(i, j) = curr
	neighbors = [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]
	for (i1, j1) in neighbors:
		new = (i1, j1)
		if 0 <= i1 < n and 0 <= j1 < m and (maze[i1][j1] != '#') and (new not in visited):
			dfs(visited, new, maze, n, m)

def prog():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		maze = [list(input().strip()) for i in range(n)]
		good = []
		bad = []
		for i in range(n):
			for j in range(m):
				if maze[i][j] == 'B':
					bad.append((i, j))
				elif maze[i][j] == 'G':
					good.append((i, j))
		if maze[n - 1][m - 1] != 'B' and len(good) == 0:
			print('Yes')
		elif maze[n - 1][m - 1] == '#' or maze[n - 1][m - 1] == 'B':
			print('No')
		else:
			failed = False
			for (i, j) in bad:
				blocks = [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]
				for (i1, j1) in blocks:
					if 0 <= i1 < n and 0 <= j1 < m:
						if maze[i1][j1] == 'G':
							failed = True
							break
						elif maze[i1][j1] != 'B':
							maze[i1][j1] = '#'
				if failed:
					break
			if failed:
				print('No')
			else:
				visited = set()
				dfs(visited, good[0], maze, n, m)
				failed = False
				for a in good:
					if a not in visited:
						failed = True
						break
				if (n - 1, m - 1) not in visited:
					failed = True
				if failed:
					print('No')
				else:
					print('Yes')
prog()


import sys
import math
import operator as op
from functools import reduce
from bisect import *
from collections import deque

def read_line():
	return sys.stdin.readline()[:-1]

def read_int():
	return int(sys.stdin.readline())

def read_int_line():
	return [int(v) for v in sys.stdin.readline().split()]

def read_float_line():
	return [float(v) for v in sys.stdin.readline().split()]

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer / denom
N = int(1000000.0) + 10
fenwick = [0] * N

def add(i, x, n):
	while i < n:
		fenwick[i] += x
		i = i | i + 1

def fsum(i, n):
	res = 0
	while i >= 0:
		res += fenwick[i]
		i = (i & i + 1) - 1
	return res

def fsum_range(i, j, n):
	return fsum(j, n) - fsum(i - 1, n)
mod = int(1000000000.0) + 7
mod2 = 998244353

def N(s):
	x = s[0]
	y = s[1]
	neighbor = []
	if x > 0:
		neighbor.append((x - 1, y))
	if x < n - 1:
		neighbor.append((x + 1, y))
	if y > 0:
		neighbor.append((x, y - 1))
	if y < m - 1:
		neighbor.append((x, y + 1))
	return neighbor
t = read_int()
for i in range(t):
	(n, m) = read_int_line()
	a = []
	for i in range(n):
		r = read_line()
		a.append(r)
	cnt = 0
	b = [[0 for i in range(m)] for j in range(n)]
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'G':
				b[i][j] = 1
				cnt += 1
			elif a[i][j] == '.':
				b[i][j] = 0
			elif a[i][j] == 'B':
				b[i][j] = 2
			else:
				b[i][j] = 3
	vis = [[False for i in range(m)] for j in range(n)]
	q = deque()
	q.append((n - 1, m - 1))
	vis[n - 1][m - 1] = True
	while len(q) != 0:
		s = q.popleft()
		for i in N(s):
			x = i[0]
			y = i[1]
			if not vis[x][y] and b[x][y] != 3:
				q.append(i)
				vis[x][y] = True
	f = True
	for i in range(n):
		for j in range(m):
			if b[i][j] == 2 and vis[i][j]:
				v = N((i, j))
				for k in v:
					x = k[0]
					y = k[1]
					if b[x][y] == 0 and vis[x][y] == True:
						b[x][y] = 3
	vis = [[False for i in range(m)] for j in range(n)]
	if b[n - 1][m - 1] == 3 and cnt == 0:
		print('Yes')
		continue
	elif b[n - 1][m - 1] == 3:
		print('No')
		continue
	q = deque()
	q.append((n - 1, m - 1))
	vis[n - 1][m - 1] = True
	while len(q) != 0:
		s = q.popleft()
		for i in N(s):
			x = i[0]
			y = i[1]
			if not vis[x][y] and b[x][y] != 3:
				q.append(i)
				vis[x][y] = True
	for i in range(n):
		for j in range(m):
			if b[i][j] == 2 and vis[i][j]:
				f = False
				break
			if b[i][j] == 1 and (not vis[i][j]):
				f = False
				break
	if f:
		print('Yes')
	else:
		print('No')


import sys
from collections import deque

def I():
	return list(map(int, input().split()))

def sieve(n):
	a = [1] * n
	for i in range(2, n):
		if a[i]:
			for j in range(i * i, n, i):
				a[j] = 0
	return a

def check(i, j):
	if matr[i][j] == 'B':
		for (x, y) in ((i + 1, j), (i - 1, j), (i, j - 1), (i, j + 1)):
			if x >= 0 and y >= 0 and (x < n) and (y < m):
				if (x, y) == (n - 1, m - 1):
					return False
				if matr[x][y] == 'G':
					return False
	return True

def bfs(i, j, good):
	q = deque()
	q.append((i, j))
	visited = set()
	while q:
		(u, v) = q.popleft()
		if (u, v) in visited:
			continue
		visited.add((u, v))
		for (x, y) in getneighs(u, v):
			if 'B' in [matr[t][l] for (t, l) in getneighs(x, y)]:
				continue
			q.append((x, y))
	for g in good:
		if g not in visited:
			return False
	return True

def getneighs(i, j):
	neighs = []
	for (x, y) in ((i + 1, j), (i - 1, j), (i, j - 1), (i, j + 1)):
		if x >= 0 and y >= 0 and (x < n) and (y < m) and (matr[x][y] != '#'):
			neighs.append((x, y))
	return neighs
for __ in range(int(input())):
	(n, m) = I()
	good = False
	goods = set()
	matr = [[] for i in range(n)]
	for i in range(n):
		matr[i] = [j for j in input()]
		if not good:
			if 'G' in matr[i]:
				good = True
	if not good:
		print('Yes')
		continue
	f = True
	for i in range(n):
		for j in range(m):
			if not check(i, j):
				f = False
			if matr[i][j] == 'G':
				goods.add((i, j))
		if not f:
			break
	if f:
		if not bfs(n - 1, m - 1, goods):
			f = False
	if f:
		print('Yes')
	else:
		print('No')


import sys
input = lambda : sys.stdin.readline().strip()

def dfs(i, j):
	vis[i][j] = True
	if i - 1 >= 0 and mat[i - 1][j] != 0:
		if not vis[i - 1][j]:
			dfs(i - 1, j)
	if i + 1 < n and mat[i + 1][j] != 0:
		if not vis[i + 1][j]:
			dfs(i + 1, j)
	if j - 1 >= 0 and mat[i][j - 1] != 0:
		if not vis[i][j - 1]:
			dfs(i, j - 1)
	if j + 1 < m and mat[i][j + 1] != 0:
		if not vis[i][j + 1]:
			dfs(i, j + 1)
t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	mat = [[] for _ in range(n)]
	for i in range(n):
		inp = input()
		for j in inp:
			if j == '#':
				mat[i].append(0)
			elif j == '.':
				mat[i].append(1)
			elif j == 'G':
				mat[i].append(2)
			elif j == 'B':
				mat[i].append(3)
	if mat[n - 1][m - 1] == 3:
		print('No')
		continue
	ok = True
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 3:
				if i - 1 >= 0 and mat[i - 1][j] == 1:
					mat[i - 1][j] = 0
				if i + 1 < n and mat[i + 1][j] == 1:
					mat[i + 1][j] = 0
				if j - 1 >= 0 and mat[i][j - 1] == 1:
					mat[i][j - 1] = 0
				if j + 1 < m and mat[i][j + 1] == 1:
					mat[i][j + 1] = 0
				if i - 1 >= 0 and mat[i - 1][j] == 2:
					ok = False
					break
				if i + 1 < n and mat[i + 1][j] == 2:
					ok = False
					break
				if j - 1 >= 0 and mat[i][j - 1] == 2:
					ok = False
					break
				if j + 1 < m and mat[i][j + 1] == 2:
					ok = False
					break
		if not ok:
			break
	if ok == False:
		print('No')
	else:
		ans = True
		vis = [[False] * m for _ in range(n)]
		if mat[n - 1][m - 1] == 1:
			dfs(n - 1, m - 1)
		ans = True
		for i in range(n):
			for j in range(m):
				if mat[i][j] == 2 and (not vis[i][j]) or (mat[i][j] == 3 and vis[i][j]):
					ans = False
					break
			if ans == False:
				break
		if ans:
			print('Yes')
		else:
			print('No')


from collections import deque

def path():
	queue = [n * m - 1]
	queue = deque(queue)
	vis = [0] * (n * m)
	vis[queue[0]] = 1
	parent = [-1] * (n * m)
	while len(queue) != 0:
		e = queue.popleft()
		vis[e] = 1
		for i in graph[e]:
			done[i] = 1
			if vis[i] == 0:
				queue.append(i)
				parent[i] = e
				vis[i] = 1
for nt in range(int(input())):
	(n, m) = map(int, input().split())
	maze = []
	for i in range(n):
		maze.append(list(input()))
	flag = 0
	ans = 'Yes'
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'B':
				if i < n - 1 and maze[i + 1][j] != 'B':
					if maze[i + 1][j] == 'G':
						flag = 1
						ans = 'No'
						break
					maze[i + 1][j] = '#'
				if j < m - 1 and maze[i][j + 1] != 'B':
					if maze[i][j + 1] == 'G':
						flag = 1
						ans = 'No'
						break
					maze[i][j + 1] = '#'
				if i > 0 and maze[i - 1][j] != 'B':
					if maze[i - 1][j] == 'G':
						flag = 1
						ans = 'No'
						break
					maze[i - 1][j] = '#'
				if j > 0 and maze[i][j - 1] != 'B':
					if maze[i][j - 1] == 'G':
						flag = 1
						ans = 'No'
						break
					maze[i][j - 1] = '#'
				maze[i][j] = '#'
		if flag:
			break
	if flag:
		print(ans)
		continue
	graph = [[] for i in range(n * m)]
	for i in range(n):
		for j in range(m):
			if maze[i][j] != '#':
				if i < n - 1 and maze[i + 1][j] != '#':
					graph[i * m + j].append((i + 1) * m + j)
				if i > 0 and maze[i - 1][j] != '#':
					graph[i * m + j].append((i - 1) * m + j)
				if j < m - 1 and maze[i][j + 1] != '#':
					graph[i * m + j].append(i * m + j + 1)
				if j > 0 and maze[i][j - 1] != '#':
					graph[i * m + j].append(i * m + j - 1)
	done = {}
	flag = 0
	path()
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'G':
				if i * m + j not in done:
					ans = 'No'
					flag = 1
					break
		if flag:
			break
	print(ans)


dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]

def valid(i, j, arr, vis):
	if i >= 0 and i < n and (j >= 0) and (j < m) and (vis[i][j] == False) and (arr[i][j] != '#') and (arr[i][j] != 'B'):
		return True
	else:
		return False

def bfs(elei, elej, mat, vis):
	q = []
	q.append([elei, elej])
	while q != []:
		u = q[0]
		q.pop(0)
		vis[u[0]][u[1]] = True
		for i in range(4):
			newx = u[0] + dx[i]
			newy = u[1] + dy[i]
			if valid(newx, newy, mat, vis):
				q.append([newx, newy])
				vis[newx][newy] = True
for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	vis = [[False for i in range(m)] for j in range(n)]
	mat = [[0 for i in range(m)] for j in range(n)]
	goo = []
	ba = []
	for i in range(n):
		s = input()
		for j in range(m):
			mat[i][j] = s[j]
			if mat[i][j] == 'G':
				goo.append([i, j])
			elif mat[i][j] == 'B':
				ba.append([i, j])
	if goo == []:
		print('Yes')
	else:
		bfs(n - 1, m - 1, mat, vis)
		ag = 1
		for g in goo:
			if vis[g[0]][g[1]] == False:
				ag = 0
		if ag == 0:
			print('No')
		else:
			vis = [[False for i in range(m)] for j in range(n)]
			ok = 1
			for b in ba:
				for i in range(4):
					newx = b[0] + dx[i]
					newy = b[1] + dy[i]
					if valid(newx, newy, mat, vis):
						if mat[newx][newy] == 'G' or (newx == n - 1 and newy == m - 1):
							ok = 0
						elif mat[newx][newy] == '.':
							mat[newx][newy] = '#'
			if ok == 0:
				print('No')
			else:
				bfs(n - 1, m - 1, mat, vis)
				ag = 1
				for g in goo:
					if vis[g[0]][g[1]] == False:
						ag = 0
				if ag == 0:
					print('No')
				else:
					print('Yes')


directions = [(0, 1), (1, 0), (-1, 0), (0, -1)]

def solve(matrix, n, m):
	for i in range(n):
		for j in range(m):
			if matrix[i][j] == 'B':
				for (di, dj) in directions:
					ni = i + di
					nj = j + dj
					if 0 <= ni < n and 0 <= nj < m:
						if matrix[ni][nj] == 'G':
							return False
						if matrix[ni][nj] != 'B':
							matrix[ni][nj] = '#'
	q = []
	visited = set()
	if matrix[-1][-1] != '#':
		q.append((n - 1, m - 1))
		visited.add((n - 1, m - 1))
	while q:
		(i, j) = q.pop()
		for (di, dj) in directions:
			ni = i + di
			nj = j + dj
			if (ni, nj) not in visited and 0 <= ni < n and (0 <= nj < m) and (matrix[ni][nj] != '#'):
				q.append((ni, nj))
				visited.add((ni, nj))
	for i in range(n):
		for j in range(m):
			if matrix[i][j] == 'G' and (i, j) not in visited:
				return False
	return True
t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	matrix = []
	for i in range(n):
		matrix.append([x for x in input()])
	if solve(matrix, n, m):
		print('Yes')
	else:
		print('No')


from sys import stdin, stdout
from collections import deque
int_in = lambda : int(stdin.readline())
arr_in = lambda : [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for y in range(rows)]
str_in = lambda : stdin.readline().strip()
out = lambda o: stdout.write('{}\n'.format(o))
arr_out = lambda o: out(' '.join(map(str, o)))
bool_out = lambda o: out('YES' if o else 'NO')
tests = lambda : range(1, int_in() + 1)
case_out = lambda i, o: out('Case #{}: {}'.format(i, o))

def solve(n, m, maze):
	g_count = 0
	for row in maze:
		for col in row:
			if col == 'G':
				g_count += 1
	if g_count == 0:
		return True
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'G':
				if i > 0 and maze[i - 1][j] == 'B':
					return False
				if i + 1 < n and maze[i + 1][j] == 'B':
					return False
				if j > 0 and maze[i][j - 1] == 'B':
					return False
				if j + 1 < m and maze[i][j + 1] == 'B':
					return False
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'B':
				if i > 0 and maze[i - 1][j] == '.':
					maze[i - 1][j] = '#'
				if i + 1 < n and maze[i + 1][j] == '.':
					maze[i + 1][j] = '#'
				if j > 0 and maze[i][j - 1] == '.':
					maze[i][j - 1] = '#'
				if j + 1 < m and maze[i][j + 1] == '.':
					maze[i][j + 1] = '#'
	if maze[n - 1][m - 1] == '#':
		return False
	dfs = deque([(n - 1, m - 1)])
	visited = set()
	while len(dfs) > 0:
		curr = dfs.pop()
		visited.add(curr)
		i = curr[0]
		j = curr[1]
		if i > 0 and (i - 1, j) not in visited and (maze[i - 1][j] != '#'):
			dfs.append((i - 1, j))
		if i + 1 < n and (i + 1, j) not in visited and (maze[i + 1][j] != '#'):
			dfs.append((i + 1, j))
		if j > 0 and (i, j - 1) not in visited and (maze[i][j - 1] != '#'):
			dfs.append((i, j - 1))
		if j + 1 < m and (i, j + 1) not in visited and (maze[i][j + 1] != '#'):
			dfs.append((i, j + 1))
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'G' and (i, j) not in visited:
				return False
			if maze[i][j] == 'B' and (i, j) in visited:
				return False
	return True
for i in tests():
	(n, m) = arr_in()
	maze = [list(str_in()) for _ in range(n)]
	out('Yes' if solve(n, m, maze) else 'No')


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
mod2 = 998244353
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

def I():
	return int(sys.stdin.readline())

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def JA(a, sep):
	return sep.join(map(str, a))

def JAA(a, s, t):
	return s.join((t.join(map(str, b)) for b in a))

def IF(c, t, f):
	return t if c else f

def YES(c):
	return IF(c, 'YES', 'NO')

def Yes(c):
	return IF(c, 'Yes', 'No')

def main():
	t = I()
	rr = []
	for _ in range(t):
		(n, m) = LI()
		aa = [S() for _ in range(n)]
		gs = []
		for i in range(n):
			s = aa[i]
			for j in range(m):
				if s[j] == 'G':
					gs.append((i, j))
		ok = 1
		t = [[0] * m for _ in range(n)]
		t[-1][-1] = -1
		for i in range(n):
			if not ok:
				break
			s = aa[i]
			for j in range(m):
				c = s[j]
				if c == '.':
					continue
				b = 0
				if c == 'G':
					b = -1
				elif c == '#':
					b = 1
				else:
					b = -1
					for (di, dj) in dd:
						ni = i + di
						nj = j + dj
						if ni < 0 or ni >= n or nj < 0 or (nj >= m) or (aa[ni][nj] == 'B'):
							continue
						if t[ni][nj] == -1:
							ok = 0
							break
						t[ni][nj] = 1
				if t[i][j] * b == -1:
					ok = 0
					break
				t[i][j] = b
		if len(gs) < 1:
			rr.append('YES')
		elif not ok:
			rr.append('NO')
		else:
			v = collections.defaultdict(bool)
			q = [(n - 1, m - 1)]
			v[n - 1, m - 1] = 1
			qi = 0
			o = [[None] * m for _ in range(n)]
			while qi < len(q):
				(i, j) = q[qi]
				qi += 1
				o[i][j] = 1
				for (di, dj) in dd:
					ni = i + di
					nj = j + dj
					if ni < 0 or ni >= n or nj < 0 or (nj >= m) or (t[ni][nj] == 1) or v[ni, nj]:
						continue
					v[ni, nj] = 1
					q.append((ni, nj))
			rr.append(YES(all((o[i][j] for (i, j) in gs))))
	return JA(rr, '\n')
print(main())


def dfs():
	while queue:
		(r, c, saw) = queue[-1]
		if not saw:
			if field[r][c] == 2:
				G_num[0] += 1
			field[r][c] = 0
			queue[-1][2] = True
		has_next = False
		for (r1, c1) in [(r + 1, c), (r - 1, c), (r, c + 1), (r, c - 1)]:
			if field[r1][c1]:
				queue.append([r1, c1, False])
				has_next = True
				break
		if not has_next:
			queue.pop()
for test_i in range(int(input())):
	(n, m) = map(int, input().split())
	field = [[0 for i in range(m + 1)]]
	G_num_origin = 0
	for r in range(n):
		row = input()
		field.append([0])
		for el in row:
			if el == '.':
				field[-1].append(1)
			elif el == '#':
				field[-1].append(0)
			elif el == 'B':
				field[-1].append('B')
			elif el == 'G':
				field[-1].append(2)
				G_num_origin += 1
		field[-1].append(0)
	field.append([0 for i in range(m + 1)])
	ans = True
	for r in range(1, n + 1):
		for c in range(1, m + 1):
			if field[r][c] == 'B':
				for (r1, c1) in [(r + 1, c), (r - 1, c), (r, c + 1), (r, c - 1)]:
					if field[r1][c1] == 'G':
						ans = False
						break
					elif field[r1][c1] != 'B':
						field[r1][c1] = 0
				field[r][c] = 0
			if not ans:
				break
		if not ans:
			break
	if not ans:
		print('No')
	elif field[n][m]:
		queue = [[n, m, False]]
		G_num = [0]
		dfs()
		print('Yes' if G_num[0] == G_num_origin else 'No')
	else:
		print('Yes' if G_num_origin == 0 else 'No')


def modify(l):
	for i in range(n):
		for j in range(m):
			if l[i][j] == 'B':
				dx = [-1, 0, 0, 1]
				dy = [0, -1, 1, 0]
				for k in range(4):
					X = i + dx[k]
					Y = j + dy[k]
					if X < 0 or X >= n:
						continue
					if Y < 0 or Y >= m:
						continue
					if l[X][Y] == 'G':
						return 0
					if l[X][Y] == '.':
						l[X][Y] = '#'
	return 1

def BFS(x):
	global dist
	global visited
	if l[x[0]][x[1]] == '#':
		return
	visited[x[0]][x[1]] = 1
	q = [x]
	dist[x[0]][x[1]] = 0
	while q != []:
		u = q[0]
		q.pop(0)
		dx = [-1, 0, 0, 1]
		dy = [0, -1, 1, 0]
		for k in range(4):
			X = u[0] + dx[k]
			Y = u[1] + dy[k]
			if X < 0 or X >= n:
				continue
			if Y < 0 or Y >= m:
				continue
			if visited[X][Y] != 1 and l[X][Y] != '#':
				q.append([X, Y])
				visited[X][Y] = 1
				dist[X][Y] = 0

def isvalid(lofgood):
	for i in lofgood:
		if dist[i[0]][i[1]] != 0:
			return 0
	return 1
t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	m = int(l[1])
	l = []
	for i in range(n):
		s = input()
		s = [k for k in s]
		l.append(s)
	if modify(l) == 0:
		print('No')
	else:
		lofgood = []
		for i in range(n):
			for j in range(m):
				if l[i][j] == 'G':
					lofgood.append([i, j])
		dist = [[-1 for i in range(m)] for j in range(n)]
		visited = [[0 for i in range(m)] for j in range(n)]
		BFS([n - 1, m - 1])
		if isvalid(lofgood):
			print('Yes')
		else:
			print('No')


class Solution:

	def __init__(self):
		for t in range(int(input())):
			self.queue = [None for i in range(50 * 50)]
			self.used = [[-1 for col in range(50)] for row in range(50)]
			(n, m) = list(map(int, input().split()))
			a = [input() for i in range(n)]
			self.solve(n, m, a, t)

	def inside(self, x, y, n, m):
		return x >= 0 and x < n and (y >= 0) and (y < m)

	def solve(self, n, m, a, t):
		totalGood = sum([1 for i in range(n) for j in range(m) if a[i][j] == 'G'])
		l = r = 0
		self.queue[0] = (n - 1, m - 1)
		self.used[n - 1][m - 1] = t
		p = [(0, -1), (0, 1), (-1, 0), (1, 0)]
		goGood = 0
		while l <= r:
			(x, y) = self.queue[l]
			l += 1
			cantSpread = False
			for (px, py) in p:
				u = x + px
				v = y + py
				if self.inside(u, v, n, m) and a[u][v] == 'B':
					cantSpread = True
					break
			if cantSpread:
				continue
			for (px, py) in p:
				u = x + px
				v = y + py
				if self.inside(u, v, n, m) and self.used[u][v] != t and (a[u][v] != 'B') and (a[u][v] != '#'):
					r += 1
					self.queue[r] = (u, v)
					self.used[u][v] = t
					goGood += 1 if a[u][v] == 'G' else 0
		if goGood < totalGood:
			return print('No')
		for i in range(n):
			for j in range(m):
				if a[i][j] == 'G':
					for (px, py) in p:
						x = i + px
						y = j + py
						if self.inside(x, y, n, m) and a[x][y] == 'B':
							return print('No')
		print('Yes')
Solution()


from collections import defaultdict
import sys
import math
input = sys.stdin.readline

class disjoint:

	def __init__(self, n, m):
		self.rank = [[1 for j in range(m)] for i in range(n)]
		self.parent = [[(i, j) for j in range(m)] for i in range(n)]

	def find(self, x, y):
		if self.parent[x][y] != (x, y):
			self.parent[x][y] = self.find(self.parent[x][y][0], self.parent[x][y][1])
		return self.parent[x][y]

	def union(self, x, y):
		xid = self.find(x[0], x[1])
		yid = self.find(y[0], y[1])
		if xid == yid:
			return
		if self.rank[xid[0]][xid[1]] < self.rank[yid[0]][yid[1]]:
			self.parent[xid[0]][xid[1]] = yid
		elif self.rank[xid[0]][xid[1]] > self.rank[yid[0]][yid[1]]:
			self.parent[yid[0]][yid[1]] = xid
		else:
			self.parent[yid[0]][yid[1]] = xid
			self.rank[xid[0]][xid[1]] += 1
a = int(input())
for i in range(a):
	(x, y) = map(int, input().split())
	(n, m) = (x, y)
	ans = []
	obj = disjoint(n, m)
	for i in range(x):
		z = input()
		t = []
		for i in range(len(z) - 1):
			t.append(z[i])
		ans.append(t)
	flag = 0
	for i in range(x):
		for j in range(y):
			if ans[i][j] == 'B':
				if i + 1 < x:
					if ans[i + 1][j] == 'G':
						flag = 1
					elif ans[i + 1][j] == '.':
						ans[i + 1][j] = '#'
				if j + 1 < y:
					if ans[i][j + 1] == 'G':
						flag = 1
					elif ans[i][j + 1] == '.':
						ans[i][j + 1] = '#'
				if i - 1 >= 0:
					if ans[i - 1][j] == 'G':
						flag = 1
					elif ans[i - 1][j] == '.':
						ans[i - 1][j] = '#'
				if j - 1 >= 0:
					if ans[i][j - 1] == 'G':
						flag = 1
					elif ans[i][j - 1] == '.':
						ans[i][j - 1] = '#'
	if flag == 1:
		print('No')
		continue
	else:
		for i in range(n):
			for j in range(m):
				if ans[i][j] == '.' or ans[i][j] == 'G':
					if i + 1 < x and (ans[i + 1][j] == '.' or ans[i + 1][j] == 'G'):
						obj.union((i, j), (i + 1, j))
					if i - 1 >= 0 and (ans[i - 1][j] == '.' or ans[i - 1][j] == 'G'):
						obj.union((i, j), (i - 1, j))
					if j + 1 < y and (ans[i][j + 1] == '.' or ans[i][j + 1] == 'G'):
						obj.union((i, j), (i, j + 1))
					if j - 1 >= 0 and (ans[i][j - 1] == '.' or ans[i][j - 1] == 'G'):
						obj.union((i, j), (i, j - 1))
		for i in range(n):
			for j in range(m):
				if ans[i][j] == 'G':
					if obj.find(i, j) != obj.find(n - 1, m - 1):
						flag = 1
		if flag == 1:
			print('No')
		else:
			print('Yes')


from bisect import bisect_left as bl
from bisect import bisect_right as br
from heapq import heappush, heappop
import math
from collections import *
from functools import reduce, cmp_to_key, lru_cache
from itertools import *
import io, os
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
M = mod = 10 ** 9 + 7

def factors(n):
	return sorted(set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0))))

def inv_mod(n):
	return pow(n, mod - 2, mod)

def li():
	return [int(i) for i in input().rstrip().split()]

def st():
	return str(input().rstrip())[2:-1]

def val():
	return int(input().rstrip())

def li2():
	return [str(i)[2:-1] for i in input().rstrip().split()]

def li3():
	return [int(i) for i in st()]
l = []
n = m = 0
change = [(1, 0), (-1, 0), (0, 1), (0, -1)]
for _ in range(val()):
	(n, m) = li()
	l = []
	ans = 'YES'
	for i in range(n):
		l.append(list(st()))
	for i in range(n):
		for j in range(m):
			if l[i][j] == 'B':
				for (dx, dy) in change:
					(x, y) = (i + dx, j + dy)
					if 0 <= x < n and 0 <= y < m and (l[x][y] == '.'):
						l[x][y] = '#'
	dp = [[0] * m for i in range(n)]
	d = deque()
	if l[-1][-1] != '#':
		d.append([n - 1, m - 1])
	visited = {}
	while d:
		(x, y) = d.popleft()
		if (x, y) in visited:
			continue
		visited[x, y] = 1
		dp[x][y] = 1
		for (dx, dy) in change:
			(i, j) = (x + dx, y + dy)
			if 0 <= i < n and 0 <= j < m and ((i, j) not in visited) and (l[i][j] != '#'):
				d.append([i, j])
	for i in range(n):
		for j in range(m):
			if dp[i][j] and l[i][j] == 'B':
				ans = 'NO'
			if not dp[i][j] and l[i][j] == 'G':
				ans = 'NO'
	print(ans)


from sys import stdin
from collections import deque
input = stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	flag = 'Yes'
	(b, g) = (0, 0)
	for x in range(n):
		t = []
		for y in input().rstrip():
			t.append(y)
		a.append(t)
		b += t.count('B')
		g += t.count('G')
	if g == 0:
		print(flag)
		continue
	for x in range(n):
		for y in range(m):
			if a[x][y] == 'B':
				if x + 1 < n:
					if a[x + 1][y] == '.':
						a[x + 1][y] = '#'
					elif a[x + 1][y] == 'G':
						flag = 'No'
						break
				if x - 1 >= 0:
					if a[x - 1][y] == '.':
						a[x - 1][y] = '#'
					elif a[x - 1][y] == 'G':
						flag = 'No'
						break
				if y + 1 < m:
					if a[x][y + 1] == '.':
						a[x][y + 1] = '#'
					elif a[x][y + 1] == 'G':
						flag = 'No'
						break
				if y - 1 >= 0:
					if a[x][y - 1] == '.':
						a[x][y - 1] = '#'
					elif a[x][y - 1] == 'G':
						flag = 'No'
						break
		if flag == 'No':
			break
	q = deque()
	chk = [[0] * 51 for x in range(51)]
	q.append([n - 1, m - 1])
	while len(q):
		(nowx, nowy) = q.popleft()
		if nowx + 1 < n and chk[nowx + 1][nowy] == 0:
			chk[nowx + 1][nowy] = 1
			if a[nowx + 1][nowy] == 'G':
				a[nowx + 1][nowy] == '.'
				g -= 1
				q.append([nowx + 1, nowy])
			elif a[nowx + 1][nowy] == '.':
				q.append([nowx + 1, nowy])
			elif a[nowx + 1][nowy] == 'B':
				flag = 'No'
				break
		if nowx - 1 >= 0 and chk[nowx - 1][nowy] == 0:
			chk[nowx - 1][nowy] = 1
			if a[nowx - 1][nowy] == 'G':
				a[nowx - 1][nowy] == '.'
				g -= 1
				q.append([nowx - 1, nowy])
			elif a[nowx - 1][nowy] == '.':
				q.append([nowx - 1, nowy])
			elif a[nowx - 1][nowy] == 'B':
				flag = 'No'
				break
		if nowy + 1 < m and chk[nowx][nowy + 1] == 0:
			chk[nowx][nowy + 1] = 1
			if a[nowx][nowy + 1] == 'G':
				a[nowx][nowy + 1] == '.'
				g -= 1
				q.append([nowx, nowy + 1])
			elif a[nowx][nowy + 1] == '.':
				q.append([nowx, nowy + 1])
			elif a[nowx][nowy + 1] == 'B':
				flag = 'No'
				break
		if nowy - 1 >= 0 and chk[nowx][nowy - 1] == 0:
			chk[nowx][nowy - 1] = 1
			if a[nowx][nowy - 1] == 'G':
				a[nowx][nowy - 1] == '.'
				g -= 1
				q.append([nowx, nowy - 1])
			elif a[nowx][nowy - 1] == '.':
				q.append([nowx, nowy - 1])
			elif a[nowx][nowy - 1] == 'B':
				flag = 'No'
				break
	if g:
		flag = 'No'
	print(flag)


import math
import sys
from itertools import permutations
from collections import defaultdict
input = sys.stdin.readline
sys.setrecursionlimit(5000)
g = []
visited = []

def DFS(v):
	visited[v] = 1
	for x in g[v]:
		if visited[x] == 0:
			DFS(x)
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	visited = [0] * (n * m)
	arr = []
	for i in range(n):
		arr.append(list(input()))
		arr[-1] = list(arr[-1])
		if arr[-1][-1] == '\n':
			arr[-1].pop()
	flag = True
	for i in range(n):
		for j in range(m - 1):
			if arr[i][j] == 'B' and arr[i][j + 1] == 'G':
				flag = False
				break
			if arr[i][j] == 'G' and arr[i][j + 1] == 'B':
				flag = False
				break
		if flag == False:
			break
	for j in range(m):
		for i in range(n - 1):
			if arr[i][j] == 'B' and arr[i + 1][j] == 'G':
				flag = False
				break
			if arr[i][j] == 'G' and arr[i + 1][j] == 'B':
				flag = False
				break
		if flag == False:
			break
	if flag == False:
		print('No')
	else:
		Garr = []
		countG = 0
		countB = 0
		for i in range(n):
			for j in range(m):
				if arr[i][j] == 'B':
					countB += 1
					if i + 1 < n and arr[i + 1][j] != 'B':
						arr[i + 1][j] = '#'
					if j + 1 < m and arr[i][j + 1] != 'B':
						arr[i][j + 1] = '#'
					if i > 0 and arr[i - 1][j] != 'B':
						arr[i - 1][j] = '#'
					if j > 0 and arr[i][j - 1] != 'B':
						arr[i][j - 1] = '#'
				if arr[i][j] == 'G':
					countG += 1
					Garr.append(i * m + j)
		g = []
		for i in range(n):
			for j in range(m):
				g.append([])
		for i in range(n):
			for j in range(m):
				if arr[i][j] != '#':
					if i + 1 < n and arr[i + 1][j] != '#':
						g[i * m + j].append((i + 1) * m + j)
						g[(i + 1) * m + j].append(i * m + j)
					if j + 1 < m and arr[i][j + 1] != '#':
						g[i * m + j].append(i * m + j + 1)
						g[i * m + j + 1].append(i * m + j)
					if i > 0 and arr[i - 1][j] != '#':
						g[i * m + j].append((i - 1) * m + j)
						g[(i - 1) * m + j].append(i * m + j)
					if j > 0 and arr[i][j - 1] != '#':
						g[i * m + j].append(i * m + j - 1)
						g[i * m + j - 1].append(i * m + j)
		try:
			DFS(n * m - 1)
		except:
			print("Here's the error")
			exit(0)
		ans = []
		for i in range(n * m):
			if visited[i] == 1:
				ans.append(i)
		if set(ans) & set(Garr) == set(Garr):
			print('Yes')
		else:
			print('No')


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
sys.setrecursionlimit(int(pow(10, 6)))
mod = int(pow(10, 9) + 7)
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
DIR = [(-1, 0), (1, 0), (0, -1), (0, 1)]

def dfs(i, j):
	if i > n or i == 0 or j > m or (j == 0):
		return
	used[i][j] = 1
	for (di, dj) in DIR:
		if not used[i + di][j + dj] and a[i + di][j + dj] != '#':
			dfs(i + di, j + dj)
for t in range(int(input())):
	(n, m) = list(map(int, input().split()))
	a = [['#'] * (m + 2)] + [list('#' + input() + '#') for i in range(n)] + [['#'] * (m + 2)]
	used = [[0] * (m + 2) for i in range(n + 2)]
	ok = True
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if a[i][j] == 'B':
				for (di, dj) in DIR:
					if a[i + di][j + dj] == 'G':
						ok = False
					elif a[i + di][j + dj] != 'B':
						a[i + di][j + dj] = '#'
	if a[n][m] != '#':
		dfs(n, m)
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if a[i][j] == 'G' and (not used[i][j]):
				ok = False
	print('Yes' if ok else 'No')


t = int(input())
for T in range(t):
	(rows, columns) = [int(i) for i in input().split()]
	maze = []
	goodppl = 0
	for row in range(rows):
		inp = input()
		maze.append([inp[i] for i in range(columns)])
		goodppl += maze[-1].count('G')
	possible = True
	if goodppl == 0:
		print('Yes')
	else:
		binaryMaze = [[0 for i in range(columns)] for q in range(rows)]
		for row in range(rows):
			for column in range(columns):
				if maze[row][column] == '#':
					binaryMaze[row][column] = 2
				elif maze[row][column] == 'G':
					binaryMaze[row][column] = 1
				elif maze[row][column] == 'B':
					if row > 0:
						binaryMaze[row - 1][column] = 2
					if row < rows - 1:
						if maze[row + 1][column] == 'G':
							possible = False
						binaryMaze[row + 1][column] = 2
					if column > 0:
						binaryMaze[row][column - 1] = 2
					if column < columns - 1:
						if maze[row][column + 1] == 'G':
							possible = False
						binaryMaze[row][column + 1] = 2
		if binaryMaze[rows - 1][columns - 1] == 2:
			possible = False
		if not possible:
			print('No')
		else:

			def getNeighboors(coor):
				(row, column) = coor
				returning = []
				if row > 0:
					returning.append((row - 1, column))
				if row < rows - 1:
					returning.append((row + 1, column))
				if column > 0:
					returning.append((row, column - 1))
				if column < columns - 1:
					returning.append((row, column + 1))
				return returning

			def check(coor, equals):
				(row, column) = coor
				return binaryMaze[row][column] == equals
			gpplcounter = 0
			queue = [(rows - 1, columns - 1)]
			visited = [[False for column in range(columns)] for row in range(rows)]

			def checkVis(coor):
				(row, column) = coor
				return visited[row][column]

			def updateVis(coor):
				(row, column) = coor
				visited[row][column] = True
			while queue:
				current = queue.pop(0)
				for nei in getNeighboors(current):
					if not checkVis(nei):
						if check(nei, 0):
							queue.append(nei)
							updateVis(nei)
						elif check(nei, 1):
							queue.append(nei)
							updateVis(nei)
							gpplcounter += 1
			if gpplcounter == goodppl:
				print('Yes')
			else:
				print('No')


from sys import stdin, stdout

class SOLVE:
	dirx = [1, 0, -1, 0]
	diry = [0, 1, 0, -1]
	n = m = None

	def bfs(self, src, graph, vis, cmd):
		good_cnt = 0
		if graph[src[0]][src[1]] == '#':
			return 0
		vis[src[0]][src[1]] = 1
		queue = [src]
		while len(queue):
			u = queue[0]
			del queue[0]
			for i in range(4):
				tmpx = u[0] + self.dirx[i]
				tmpy = u[1] + self.diry[i]
				if 0 <= tmpx <= self.n - 1 and 0 <= tmpy <= self.m - 1 and (vis[tmpx][tmpy] == 0) and (graph[tmpx][tmpy] != '#'):
					vis[tmpx][tmpy] = 1
					if cmd == 'block_bad':
						if graph[tmpx][tmpy] == '.':
							graph[tmpx][tmpy] = '#'
						else:
							queue.append((tmpx, tmpy))
					elif cmd == 'escape_good':
						if graph[tmpx][tmpy] == 'G':
							good_cnt += 1
						queue.append((tmpx, tmpy))
		if cmd == 'escape_good':
			return good_cnt
		return 0

	def solve(self):
		R = stdin.readline
		W = stdout.write
		ans = []
		for i in range(int(R())):
			(self.n, self.m) = [int(x) for x in R().split()]
			graph = []
			for j in range(self.n):
				graph.append(list(R()))
			bad_p = []
			good_cnt = 0
			for j in range(self.n):
				for k in range(self.m):
					if graph[j][k] == 'B':
						bad_p.append((j, k))
					elif graph[j][k] == 'G':
						good_cnt += 1
			vis = [[0 for k in range(self.m)] for j in range(self.n)]
			for p in bad_p:
				self.bfs(p, graph, vis, 'block_bad')
			vis = [[0 for k in range(self.m)] for j in range(self.n)]
			final_good_cnt = self.bfs((self.n - 1, self.m - 1), graph, vis, 'escape_good')
			if final_good_cnt == good_cnt:
				ans.append('yes')
			else:
				ans.append('no')
		W('\n'.join(ans))
		return 0

def main():
	s = SOLVE()
	s.solve()
main()


inp = input
dirr = [(-1, 0), (1, 0), (0, -1), (0, 1)]
for _ in range(int(inp())):
	(n, m) = map(int, inp().strip().split(' '))
	rows = []
	for __ in range(n):
		rows.append(list(inp().strip()))
	flag = True
	goods = 0
	for i in range(n):
		for j in range(m):
			if rows[i][j] == 'G':
				goods += 1
			elif rows[i][j] == 'B':
				if i > 0:
					if rows[i - 1][j] == 'G':
						flag = False
						break
					elif rows[i - 1][j] == '.':
						rows[i - 1][j] = '#'
				if i < n - 1:
					if rows[i + 1][j] == 'G':
						flag = False
						break
					elif rows[i + 1][j] == '.':
						rows[i + 1][j] = '#'
				if j > 0:
					if rows[i][j - 1] == 'G':
						flag = False
						break
					elif rows[i][j - 1] == '.':
						rows[i][j - 1] = '#'
				if j < m - 1:
					if rows[i][j + 1] == 'G':
						flag = False
						break
					elif rows[i][j + 1] == '.':
						rows[i][j + 1] = '#'
	if not flag:
		print('No')
		continue
	backg = 0
	stack = [(n - 1, m - 1)]
	vis = [[False] * m for i in range(n)]
	while len(stack) > 0:
		newtodo = []
		for stck in stack:
			(a, b) = stck
			if rows[a][b] == '#' or vis[a][b]:
				continue
			vis[a][b] = True
			if a > 0:
				newtodo.append((a - 1, b))
			if b > 0:
				newtodo.append((a, b - 1))
			if a < n - 1:
				newtodo.append((a + 1, b))
			if b < m - 1:
				newtodo.append((a, b + 1))
		stack = newtodo
	for i in range(n):
		for j in range(m):
			if rows[i][j] == 'G' and (not vis[i][j]):
				flag = False
				break
	if flag:
		print('Yes')
	else:
		print('No')


import sys
input = sys.stdin.readline
from collections import *

def bfs():
	q = deque([])
	dist = [[-1] * m for _ in range(n)]
	if S[n - 1][m - 1] != '#':
		q = deque([(n - 1, m - 1)])
		dist[n - 1][m - 1] = 0
	while q:
		(cx, cy) = q.popleft()
		for (nx, ny) in [(cx - 1, cy), (cx + 1, cy), (cx, cy - 1), (cx, cy + 1)]:
			if 0 <= nx < n and 0 <= ny < m and (S[nx][ny] != '#') and (dist[nx][ny] == -1):
				dist[nx][ny] = dist[cx][cy] + 1
				q.append((nx, ny))
	return dist
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	S = [list(input()[:-1]) for _ in range(n)]
	for i in range(n):
		for j in range(m):
			if S[i][j] == 'B':
				for (ni, nj) in [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]:
					if 0 <= ni < n and 0 <= nj < m and (S[ni][nj] == '.'):
						S[ni][nj] = '#'
	dist = bfs()
	ok = True
	ng = False
	for i in range(n):
		for j in range(m):
			if S[i][j] == 'G' and dist[i][j] == -1:
				ok = False
			if S[i][j] == 'B' and dist[i][j] != -1:
				ng = True
	if ok and (not ng):
		print('Yes')
	else:
		print('No')


import sys
sys.setrecursionlimit(100000)
dir = [(-1, 0), (1, 0), (0, -1), (0, 1)]

def dfs(i, j):
	visited[i][j] = True
	for (di, dj) in dir:
		if di + i < 0 or di + i >= n or dj + j < 0 or (dj + j >= m):
			continue
		if not visited[i + di][j + dj] and maze[i + di][j + dj] != '#':
			dfs(i + di, j + dj)
t = int(input())
for a in range(t):
	(n, m) = list(map(int, input().split()))
	maze = [list(input()) for i in range(n)]
	answer = True
	for i in range(0, n):
		if not answer:
			break
		for j in range(0, m):
			if not answer:
				break
			if maze[i][j] == 'B':
				for (di, dj) in dir:
					if di + i < 0 or di + i >= n or dj + j < 0 or (dj + j >= m):
						continue
					if maze[i + di][j + dj] == 'G':
						answer = False
						break
					elif maze[i + di][j + dj] != 'B':
						maze[i + di][j + dj] = '#'
	if answer:
		visited = [[False] * m for i in range(n)]
		if maze[n - 1][m - 1] != '#':
			dfs(n - 1, m - 1)
		for i in range(0, n):
			for j in range(0, m):
				if maze[i][j] == 'G' and (not visited[i][j]):
					answer = False
	print('Yes' if answer else 'No')


import collections

def f():
	(n, m) = [int(s) for s in input().split()]
	M = []
	for _ in range(n):
		M.append(list(input()))
	steps = [(0, 1), (0, -1), (1, 0), (-1, 0)]

	def checkValid(i, j):
		if i < 0:
			return False
		if i >= n:
			return False
		if j < 0:
			return False
		if j >= m:
			return False
		return True

	def checkBRound(i0, j0):
		for (x, y) in steps:
			(i, j) = (i0 + x, j0 + y)
			if checkValid(i, j):
				if M[i][j] == 'G':
					return False
				if M[i][j] == '.':
					M[i][j] = '#'
		return True

	def haveGood():
		for i in range(n):
			for j in range(m):
				if M[i][j] == 'G':
					return True
		return False
	if not haveGood():
		print('Yes')
		return
	for i in range(n):
		for j in range(m):
			if M[i][j] == 'B':
				if not checkBRound(i, j):
					print('No')
					return
	if M[n - 1][m - 1] == '#':
		print('No')
		return
	q = collections.deque()
	q.append((n - 1, m - 1))
	while q:
		(i0, j0) = q.popleft()
		for (x, y) in steps:
			(i, j) = (i0 + x, j0 + y)
			if checkValid(i, j):
				if M[i][j] == '.' or M[i][j] == 'G':
					M[i][j] = ''
					q.append((i, j))
	if haveGood():
		print('No')
		return
	print('Yes')
for t in range(int(input())):
	f()


from collections import *
from itertools import *
from string import *
from bisect import *
from queue import *
from heapq import *
from math import *
from sys import *
from re import *

def fast():
	return stdin.readline().strip()

def zzz():
	return [int(i) for i in fast().split()]
(z, zz) = (input, lambda : list(map(int, z().split())))
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def output(answer):
	stdout.write(str(answer))
dx = [-1, 1, 0, 0, 1, -1, 1, -1]
dy = [0, 0, 1, -1, 1, -1, -1, 1]
num = int(z())
for _ in range(num):
	(n, m) = zzz()
	lst = []
	for i in range(n):
		lst.append(list(fast()))
	g_cnt = 0
	g_vis = 0
	for i in range(n):
		for j in range(m):
			c = lst[i][j]
			if c == 'G':
				g_cnt += 1
			elif c == 'B':
				for d in range(4):
					(x, y) = (i + dx[d], j + dy[d])
					if 0 <= x < n and 0 <= y < m:
						if lst[x][y] == '.':
							lst[x][y] = '#'
	vis = [[False] * m for _ in ' ' * n]
	stack = []
	if lst[n - 1][m - 1] != '#':
		stack.append((n - 1, m - 1))
		vis[n - 1][m - 1] = True
	ans = True
	while stack:
		(x, y) = stack.pop()
		if lst[x][y] == 'B':
			ans = False
			break
		if lst[x][y] == 'G':
			g_vis += 1
		for i in range(4):
			(a, b) = (x + dx[i], y + dy[i])
			if 0 <= a < n and 0 <= b < m:
				if not vis[a][b] and lst[a][b] != '#':
					vis[a][b] = True
					stack.append((a, b))
	print('Yes' if ans and g_vis == g_cnt else 'No')


from collections import defaultdict
import sys
buff_readline = sys.stdin.readline
readline = sys.stdin.readline
INF = 2 ** 62 - 1

def read_int():
	return int(buff_readline())

def read_int_n():
	return list(map(int, buff_readline().split()))

def read_float():
	return float(buff_readline())

def read_float_n():
	return list(map(float, buff_readline().split()))

def read_str():
	return readline().strip()

def read_str_n():
	return readline().strip().split()

def error_print(*args):
	print(*args, file=sys.stderr)

def mt(f):
	import time

	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		error_print(e - s, 'sec')
		return ret
	return wrap

class UnionFind:

	def __init__(self):
		self.__table = {}
		self.__size = defaultdict(lambda : 1)
		self.__rank = defaultdict(lambda : 1)

	def __root(self, x):
		if x not in self.__table:
			self.__table[x] = x
		elif x != self.__table[x]:
			self.__table[x] = self.__root(self.__table[x])
		return self.__table[x]

	def same(self, x, y):
		return self.__root(x) == self.__root(y)

	def union(self, x, y):
		x = self.__root(x)
		y = self.__root(y)
		if x == y:
			return False
		if self.__rank[x] < self.__rank[y]:
			self.__table[x] = y
			self.__size[y] += self.__size[x]
		else:
			self.__table[y] = x
			self.__size[x] += self.__size[y]
			if self.__rank[x] == self.__rank[y]:
				self.__rank[x] += 1
		return True

	def size(self, x):
		return self.__size[self.__root(x)]

	def num_of_group(self):
		g = 0
		for (k, v) in self.__table.items():
			if k == v:
				g += 1
		return g

def slv(N, M, G):
	G = [[c for c in r] for r in G]
	for i in range(N):
		for j in range(M):
			if G[i][j] == 'B':
				if i > 0:
					if G[i - 1][j] == 'G':
						return 'No'
					elif G[i - 1][j] != 'B':
						G[i - 1][j] = '#'
				if i < N - 1:
					if G[i + 1][j] == 'G':
						return 'No'
					elif G[i + 1][j] != 'B':
						G[i + 1][j] = '#'
				if j > 0:
					if G[i][j - 1] == 'G':
						return 'No'
					elif G[i][j - 1] != 'B':
						G[i][j - 1] = '#'
				if j < M - 1:
					if G[i][j + 1] == 'G':
						return 'No'
					elif G[i][j + 1] != 'B':
						G[i][j + 1] = '#'
	uf = UnionFind()
	g = (N - 1, M - 1)
	q = [g]
	done = set()
	done.add(g)
	while q:
		(i, j) = q.pop()
		for (dx, dy) in [(-1, 0), (0, -1), (0, 1), (1, 0)]:
			x = i + dx
			y = j + dy
			if (x, y) in done:
				continue
			if 0 <= x < N and 0 <= y < M and (G[x][y] != '#'):
				uf.union(g, (x, y))
				q.append((x, y))
				done.add((x, y))
	gc = 0
	for i in range(N):
		for j in range(M):
			if G[i][j] == 'G':
				if not uf.same(g, (i, j)):
					return 'No'
				gc += 1
	if gc > 0 and G[N - 1][M - 1] == '#' or G[N - 1][M - 1] == 'B':
		return 'No'
	return 'Yes'

def main():
	T = read_int()
	for _ in range(T):
		(N, M) = read_int_n()
		G = [read_str() for _ in range(N)]
		print(slv(N, M, G))
main()


import sys
import math
import collections
sys.setrecursionlimit(10 ** 6)
x = [0, 0, 1, -1]
y = [1, -1, 0, 0]
moves = list(zip(x, y))

def isValid(x, y, n, m):
	return x >= 0 and x < n and (y >= 0) and (y < m)

def bfs(grid, x, y, n, m):
	for mo in moves:
		nx = x + mo[0]
		ny = y + mo[1]
		if isValid(nx, ny, n, m):
			if grid[nx][ny] == 'G' or grid[nx][ny] == '.':
				grid[nx][ny] = 'Y'
				bfs(grid, nx, ny, n, m)
t = int(sys.stdin.readline().strip())
for i in range(t):
	(n, m) = list(map(int, sys.stdin.readline().strip().split(' ')))
	grid = []
	hasGood = False
	for i in range(n):
		l = list(sys.stdin.readline().strip())
		if 'G' in l:
			hasGood = True
		grid.append(l)
	if not hasGood:
		print('Yes')
	else:
		isPossible = True
		for i in range(len(grid)):
			for j in range(len(grid[0])):
				if grid[i][j] == 'B':
					for e in moves:
						nx = i + e[0]
						ny = j + e[1]
						if isValid(nx, ny, n, m):
							if grid[nx][ny] != 'G' and grid[nx][ny] != 'B':
								grid[nx][ny] = '#'
							elif grid[nx][ny] == 'G':
								isPossible = False
								break
				if not isPossible:
					break
			if not isPossible:
				break
		if not isPossible:
			print('No')
		elif grid[n - 1][m - 1] == '#':
			print('No')
		else:
			bfs(grid, n - 1, m - 1, n, m)
			possible = True
			for i in range(len(grid)):
				for j in range(len(grid[0])):
					if grid[i][j] == 'G':
						possible = False
						break
				if not possible:
					break
			if possible:
				print('Yes')
			else:
				print('No')


from sys import stdin, setrecursionlimit
input = lambda : stdin.readline().strip()
setrecursionlimit(100000)

def block(x, y):
	if x + 1 < n:
		if arr[x + 1][y] == 'G':
			return 1
		arr[x + 1][y] = '#'
	if x:
		if arr[x - 1][y] == 'G':
			return 1
		arr[x - 1][y] = '#'
	if y + 1 < m:
		if arr[x][y + 1] == 'G':
			return 1
		arr[x][y + 1] = '#'
	if y:
		if arr[x][y - 1] == 'G':
			return 1
		arr[x][y - 1] = '#'

def dfs(x, y):
	global cnt
	if arr[x][y] == 'G':
		cnt += 1
	arr[x][y] = '#'
	if x + 1 < n and arr[x + 1][y] != '#':
		dfs(x + 1, y)
	if x and arr[x - 1][y] != '#':
		dfs(x - 1, y)
	if y + 1 < m and arr[x][y + 1] != '#':
		dfs(x, y + 1)
	if y and arr[x][y - 1] != '#':
		dfs(x, y - 1)
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	g = 0
	b = []
	arr = []
	for i in range(n):
		s = input()
		for j in range(m):
			if s[j] == 'G':
				g += 1
			elif s[j] == 'B':
				b.append([i, j])
		arr.append(list(s))
	ans = 'YES'
	cnt = 0
	for (i, j) in b:
		if block(i, j):
			ans = 'NO'
			break
	if ans == 'NO' or (arr[-1][-1] == '#' and g):
		print('NO')
		continue
	dfs(n - 1, m - 1)
	print('YES' if cnt == g else 'NO')


def yn(arr, n, m):
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'B':
				if j - 1 >= 0 and arr[i][j - 1] != 'G' and (arr[i][j - 1] != 'B'):
					arr[i][j - 1] = '#'
				if j + 1 < m and arr[i][j + 1] != 'G' and (arr[i][j + 1] != 'B'):
					arr[i][j + 1] = '#'
				if i - 1 >= 0 and arr[i - 1][j] != 'G' and (arr[i - 1][j] != 'B'):
					arr[i - 1][j] = '#'
				if i + 1 < n and arr[i + 1][j] != 'G' and (arr[i + 1][j] != 'B'):
					arr[i + 1][j] = '#'
				if j - 1 >= 0 and arr[i][j - 1] == 'G':
					return 1
				if j + 1 < m and arr[i][j + 1] == 'G':
					return 1
				if i - 1 >= 0 and arr[i - 1][j] == 'G':
					return 1
				if i + 1 < n and arr[i + 1][j] == 'G':
					return 1
	return 0

def dfs(i, j, n, m):
	if arr[i][j] == '#':
		return 0
	ans = 0
	if arr[i][j] == 'G':
		ans += 1
	arr[i][j] = '#'
	if i > 0:
		ans += dfs(i - 1, j, n, m)
	if i < n - 1:
		ans += dfs(i + 1, j, n, m)
	if j > 0:
		ans += dfs(i, j - 1, n, m)
	if j < m - 1:
		ans += dfs(i, j + 1, n, m)
	return ans
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	ng = 0
	for i in range(n):
		arr.append(list(input()))
		ng += arr[-1].count('G')
	if yn(arr, n, m):
		print('No')
	elif dfs(n - 1, m - 1, n, m) == ng:
		print('Yes')
	else:
		print('No')


import sys
LI = lambda : list(map(int, sys.stdin.readline().strip('\n').split()))
MI = lambda : map(int, sys.stdin.readline().strip('\n').split())
SI = lambda : sys.stdin.readline().strip('\n')
II = lambda : int(sys.stdin.readline().strip('\n'))

def check(i, j):
	global n, m, g, vis
	return 0 <= i < n and 0 <= j < m and (g[i][j] != '#') and (not vis[i][j])
for _ in range(II()):
	(n, m) = MI()
	(g, num) = ([], 0)
	for i in range(n):
		g.append(list(SI()))
		num += g[-1].count('G')
	for i in range(n):
		for j in range(m):
			if g[i][j] == 'B':
				if i + 1 < n and g[i + 1][j] != 'B':
					g[i + 1][j] = '#'
				if i - 1 >= 0 and g[i - 1][j] != 'B':
					g[i - 1][j] = '#'
				if j + 1 < m and g[i][j + 1] != 'B':
					g[i][j + 1] = '#'
				if j - 1 >= 0 and g[i][j - 1] != 'B':
					g[i][j - 1] = '#'
	(q, vis) = ([(n - 1, m - 1)], [[False for j in range(m)] for i in range(n)])
	cnt = 0
	if g[n - 1][m - 1] != '#':
		while q:
			(u, v) = q.pop()
			if vis[u][v]:
				continue
			vis[u][v] = True
			if g[u][v] == 'G':
				cnt += 1
			if check(u + 1, v):
				q.append((u + 1, v))
			if check(u - 1, v):
				q.append((u - 1, v))
			if check(u, v + 1):
				q.append((u, v + 1))
			if check(u, v - 1):
				q.append((u, v - 1))
	print('Yes' if cnt == num else 'No')


def dfs(x, y):
	vis[x][y] = 1
	for i in range(4):
		if x + dx[i] >= 0 and x + dx[i] < n and (y + dy[i] >= 0) and (y + dy[i] < m):
			if (g[x + dx[i]][y + dy[i]] == '.' or g[x + dx[i]][y + dy[i]] == 'G') and vis[x + dx[i]][y + dy[i]] == 0:
				dfs(x + dx[i], y + dy[i])
from collections import deque
for x in range(int(input())):
	(n, m) = list(map(int, input().split()))
	g = []
	for i in range(n):
		g.append(list(input()))
	dx = [0, 0, 1, -1]
	dy = [1, -1, 0, 0]
	r = 1
	c = 0
	for x in range(n):
		for y in range(m):
			if g[x][y] == 'B':
				for i in range(4):
					if x + dx[i] >= 0 and x + dx[i] < n and (y + dy[i] >= 0) and (y + dy[i] < m):
						if g[x + dx[i]][y + dy[i]] == '.':
							g[x + dx[i]][y + dy[i]] = '#'
						elif g[x + dx[i]][y + dy[i]] == 'G':
							r = 0
							break
			elif g[x][y] == 'G':
				c += 1
	if r == 0:
		print('No')
	elif c > 0 and g[n - 1][m - 1] == '#':
		print('No')
	else:
		r = 1
		q = deque()
		vis = [[0 for j in range(m)] for i in range(n)]
		dfs(n - 1, m - 1)
		for x in range(n):
			for y in range(m):
				if g[x][y] == 'G' and vis[x][y] == 0:
					r = 0
					break
		print('Yes' if r == 1 else 'No')


import sys

def input():
	return sys.stdin.readline().strip()

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

def MAP():
	return map(int, input().split())

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 19
MOD = 10 ** 9 + 7

def build_grid(H, W, intv, _type, space=True, padding=False):
	if space:
		_input = lambda : input().split()
	else:
		_input = lambda : input()
	_list = lambda : list(map(_type, _input()))
	if padding:
		offset = 1
	else:
		offset = 0
	grid = list2d(H + offset * 2, W + offset * 2, intv)
	for i in range(offset, H + offset):
		row = _list()
		for j in range(offset, W + offset):
			grid[i][j] = row[j - offset]
	return grid

def bfs(grid, src):
	from collections import deque
	(H, W) = (len(grid), len(grid[0]))
	directions = ((1, 0), (-1, 0), (0, 1), (0, -1))
	dist = list2d(H, W, INF)
	que = deque()
	for (h, w) in src:
		if grid[h][w] == '#':
			return dist
		que.append((h, w))
		dist[h][w] = 0
	while que:
		(h, w) = que.popleft()
		for (dh, dw) in directions:
			h2 = h + dh
			w2 = w + dw
			if grid[h2][w2] == '#':
				continue
			if dist[h2][w2] != INF:
				continue
			dist[h2][w2] = dist[h][w] + 1
			que.append((h2, w2))
	return dist
for _ in range(INT()):
	(H, W) = MAP()
	grid = build_grid(H, W, '#', str, space=0, padding=1)
	ng = False
	directions = ((1, 0), (-1, 0), (0, 1), (0, -1))
	for i in range(1, H + 1):
		for j in range(1, W + 1):
			if grid[i][j] == 'B':
				for (di, dj) in directions:
					ii = i + di
					jj = j + dj
					if grid[ii][jj] == 'B':
						continue
					if grid[ii][jj] == 'G':
						ng = True
						break
					grid[ii][jj] = '#'
				if ng:
					break
		if ng:
			break
	if ng:
		No()
		continue
	res = bfs(grid, [(H, W)])
	for i in range(1, H + 1):
		for j in range(1, W + 1):
			if grid[i][j] == 'G' and res[i][j] == INF:
				ng = True
				break
		if ng:
			break
	if ng:
		No()
		continue
	Yes()


def readintlst():
	return list(map(int, input().split(' ')))

def readcharlst():
	return list(input().split(' '))

def readn():
	return int(input())
directions = [(1, 0), (-1, 0), (0, 1), (0, -1)]

def main(n, m, mat):
	gg = set()
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 'B':
				for (di, dj) in directions:
					(ii, jj) = (i + di, j + dj)
					if 0 <= ii < n and 0 <= jj < m:
						if mat[ii][jj] == 'G':
							return False
						elif mat[ii][jj] == '.':
							mat[ii][jj] = '#'
			if mat[i][j] == 'G':
				gg.add((i, j))
	q = [(n - 1, m - 1)]
	visited = set((n - 1, m - 1))
	if mat[n - 1][m - 1] == '#':
		if gg:
			return False
		else:
			return True
	while q:
		nq = []
		for (i, j) in q:
			for (di, dj) in directions:
				(ii, jj) = (i + di, j + dj)
				if 0 <= ii < n and 0 <= jj < m and ((ii, jj) not in visited) and (mat[ii][jj] != '#'):
					visited.add((ii, jj))
					nq.append((ii, jj))
					if (ii, jj) in gg:
						gg.remove((ii, jj))
		q = nq
	if gg:
		return False
	else:
		return True
for _ in range(readn()):
	(n, m) = readintlst()
	mat = []
	for _ in range(n):
		mat.append(list(input()))
	if main(n, m, mat):
		print('yes')
	else:
		print('no')


t = int(input())
for _ in range(t):
	(n, m) = [int(x) for x in input().split()]
	grid = [list(input()) for _ in range(n)]
	has_good = any(('G' in l for l in grid))
	if not has_good:
		print('Yes')
		continue
	impossible = False
	for i in range(n):
		for j in range(m):
			if grid[i][j] != 'B':
				continue
			for (nbi, nbj) in [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]:
				if 0 <= nbi < n and 0 <= nbj < m:
					if grid[nbi][nbj] == 'G':
						impossible = True
						break
					elif grid[nbi][nbj] == 'B' or grid[nbi][nbj] == '#':
						continue
					elif grid[nbi][nbj] == '.':
						grid[nbi][nbj] = '#'
					else:
						assert False, "What's in the grid?"
	if grid[n - 1][m - 1] == '#' or impossible:
		print('No')
		continue
	seen = [[False] * m for _ in range(n)]
	stack = [(n - 1, m - 1)]
	seen[n - 1][m - 1] = True
	while len(stack):
		(i, j) = stack.pop()
		for (nbi, nbj) in [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]:
			if 0 <= nbi < n and 0 <= nbj < m:
				if grid[nbi][nbj] != '#' and (not seen[nbi][nbj]):
					seen[nbi][nbj] = True
					stack.append((nbi, nbj))
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 'G' and (not seen[i][j]):
				impossible = True
				break
		if impossible:
			break
	if impossible:
		print('No')
	else:
		print('Yes')


from sys import stdin, stdout

def INI():
	return int(stdin.readline())

def INL():
	return [int(_) for _ in stdin.readline().split()]

def INS():
	return stdin.readline()

def MOD():
	return pow(10, 9) + 7

def OPS(ans):
	stdout.write(str(ans) + '\n')

def OPL(ans):
	[stdout.write(str(_) + ' ') for _ in ans]
	stdout.write('\n')

def make(i, j):
	if 0 <= i - 1 < n and 0 <= j < m and (X[i - 1][j] == '.'):
		X[i - 1][j] = '#'
	if 0 <= i + 1 < n and 0 <= j < m and (X[i + 1][j] == '.'):
		X[i + 1][j] = '#'
	if 0 <= i < n and 0 <= j - 1 < m and (X[i][j - 1] == '.'):
		X[i][j - 1] = '#'
	if 0 <= i < n and 0 <= j + 1 < m and (X[i][j + 1] == '.'):
		X[i][j + 1] = '#'

def is_safe(i, j):
	return 0 <= i < n and 0 <= j < m

def dfs(i, j):
	global ans
	if X[i][j] == 'G':
		ans -= 1
	V[i][j] = True
	for (_, __) in [[i - 1, j], [i + 1, j], [i, j + 1], [i, j - 1]]:
		if is_safe(_, __) and (not V[_][__]):
			if X[_][__] == 'B':
				global f
				f = 1
			elif X[_][__] in '.G':
				dfs(_, __)
for _ in range(INI()):
	(n, m) = INL()
	X = []
	V = [[False for _ in range(m)] for _ in range(n)]
	ans = 0
	f = 0
	for _ in range(n):
		x = list(input())
		ans += x.count('G')
		X.append(x)
	for _ in range(n):
		for __ in range(m):
			if X[_][__] == 'B':
				make(_, __)
	if X[n - 1][m - 1] != '#':
		dfs(n - 1, m - 1)
	if not ans and (not f):
		OPS('Yes')
	else:
		OPS('No')


import sys, io, os, time
from collections import defaultdict
from collections import OrderedDict
from collections import deque
from itertools import combinations
from itertools import permutations
import bisect, math, heapq
alphabet = 'abcdefghijklmnopqrstuvwxyz'
input = sys.stdin.readline
dirr = [[1, 0], [0, 1], [-1, 0], [0, -1]]

def valid(i, j, n, m):
	return 0 <= i <= n - 1 and 0 <= j <= m - 1
for ii in range(int(input())):
	(n, m) = map(int, input().split())
	arr = [list(input()) for i in range(n)]
	visited = [[False] * (m + 1) for i in range(n + 1)]
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'B':
				for (x, y) in dirr:
					nx = x + i
					ny = y + j
					if valid(nx, ny, n, m) and arr[nx][ny] == '.':
						arr[nx][ny] = '#'
	q = deque()
	if arr[n - 1][m - 1] == '.':
		q.append([n - 1, m - 1])
		visited[n - 1][m - 1] = True
	while q:
		(i, j) = q.popleft()
		for (x, y) in dirr:
			nx = i + x
			ny = j + y
			if valid(nx, ny, n, m) and (not visited[nx][ny]) and (arr[nx][ny] != '#'):
				q.append([nx, ny])
				visited[nx][ny] = True
	ok = True
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'G' and (not visited[i][j]) or (arr[i][j] == 'B' and visited[i][j]):
				ok = False
				break
	if ok:
		print('Yes')
	else:
		print('No')


def bfs(i, j):
	q = [(i, j)]
	vis = {}
	vis[i, j] = 1
	dx = [-1, 1, 0, 0]
	dy = [0, 0, 1, -1]
	c = 0
	while q:
		(x, y) = q.pop(0)
		for i in range(4):
			tx = x + dx[i]
			ty = y + dy[i]
			if 0 <= tx < n and 0 <= ty < m:
				if (tx, ty) in vis:
					pass
				elif dp[tx][ty] == '.':
					q.append((tx, ty))
					vis[tx, ty] = 1
				elif dp[tx][ty] == 'G':
					q.append((tx, ty))
					vis[tx, ty] = 1
					c += 1
				elif dp[tx][ty] == '#':
					pass
				else:
					return -1
	return c
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	dp = [[0] * m for _ in range(n)]
	ct = 0
	for i in range(n):
		s = input()
		for j in range(m):
			dp[i][j] = s[j]
			if s[j] == 'G':
				ct += 1
	for i in range(n):
		for j in range(m):
			if dp[i][j] == '.':
				if i - 1 >= 0 and dp[i - 1][j] == 'B':
					tf = True
				elif i + 1 < n and dp[i + 1][j] == 'B':
					tf = True
				elif j - 1 >= 0 and dp[i][j - 1] == 'B':
					tf = True
				elif j + 1 < m and dp[i][j + 1] == 'B':
					tf = True
				else:
					tf = False
				if tf:
					dp[i][j] = '#'
	if dp[-1][-1] == '#':
		if ct == 0:
			print('YES')
		else:
			print('NO')
	else:
		tp = bfs(n - 1, m - 1)
		if tp == -1:
			print('NO')
		elif tp == ct:
			print('YES')
		else:
			print('NO')


import sys
t = int(input())
for _t in range(t):
	(n, m) = map(int, sys.stdin.readline().split())
	L = []
	goods = []
	bads = []
	for i in range(n):
		row = list(input())
		for (j, cell) in enumerate(row):
			if cell == 'B':
				bads.append((i, j))
			elif cell == 'G':
				goods.append((i, j))
		L.append(row)
	go_next = False
	for (i, j) in bads:
		for (di, dj) in ((1, 0), (-1, 0), (0, -1), (0, 1)):
			if n > i + di > -1 and m > j + dj > -1:
				if L[i + di][j + dj] == 'G':
					print('No')
					go_next = True
					break
				elif L[i + di][j + dj] != 'B':
					L[i + di][j + dj] = '#'
		if go_next:
			break
	if go_next:
		continue
	if L[n - 1][m - 1] == '#':
		if goods:
			print('No')
		else:
			print('Yes')
		continue
	for (i, j) in goods:
		L[i][j] = '.'
	for (person_id, good_person) in enumerate(goods, 1):
		(gi, gj) = good_person
		check = [(gi, gj)]
		L[gi][gj] = person_id
		next_person = False
		while check:
			new_check = []
			for (i, j) in check:
				for (di, dj) in ((1, 0), (-1, 0), (0, -1), (0, 1)):
					if n > i + di > -1 and m > j + dj > -1:
						cell = L[i + di][j + dj]
						if type(cell) is int:
							if cell < person_id:
								next_person = True
								break
							continue
						if cell == '#':
							continue
						L[i + di][j + dj] = person_id
						new_check.append((i + di, j + dj))
			check = new_check
		if next_person:
			continue
		if L[n - 1][m - 1] != person_id:
			print('No')
			go_next = True
			break
	if go_next:
		continue
	print('Yes')


from sys import stdin, stdout
import collections
import heapq
import itertools
import functools
import math
import operator
import string
ALPHABET = string.ascii_lowercase
DIGITS = string.digits

def read_line():
	return stdin.readline().strip()

def read_int():
	return int(read_line())

def read_arr():
	return read_line().split(' ')

def read_int_arr():
	return [int(x) for x in read_arr()]

def query_interactive(s):
	print(s)
	stdout.flush()

def solve():
	(n, m) = read_int_arr()
	maze = []
	for _ in range(n):
		maze.append(list(read_line()))
	Gs = set()
	for r in range(n):
		for c in range(m):
			if maze[r][c] == 'B':
				for (rr, cc) in [(r + 1, c), (r, c + 1), (r - 1, c), (r, c - 1)]:
					if 0 <= rr < n and 0 <= cc < m:
						if maze[rr][cc] == 'B':
							continue
						if maze[rr][cc] == 'G':
							print('NO')
							return
						else:
							maze[rr][cc] = '#'
			elif maze[r][c] == 'G':
				Gs.add((r, c))
	if len(Gs) == 0:
		print('Yes')
		return
	seen = set()
	found = set()
	bfs = collections.deque([(n - 1, m - 1)])
	while bfs:
		(r, c) = bfs.popleft()
		if (r, c) in seen:
			continue
		if not (0 <= r < n and 0 <= c < m):
			continue
		if maze[r][c] == '#':
			continue
		if (r, c) in Gs:
			found.add((r, c))
		seen.add((r, c))
		for (rr, cc) in [(r + 1, c), (r, c + 1), (r - 1, c), (r, c - 1)]:
			bfs.append((rr, cc))
	if len(found) != len(Gs):
		print('No')
	else:
		print('Yes')

def main():
	T = 1
	T = read_int()
	for _ in range(T):
		solve()
main()


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

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

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

def N():
	return int(input())
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return flag

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d

def GP(it):
	return [[ch, len(list(g))] for (ch, g) in groupby(it)]

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None

@bootstrap
def dfs(i, j):
	vis.add((i, j))
	global c
	if g[i][j] == 'G':
		c -= 1
	for (ni, nj) in [[i + 1, j], [i - 1, j], [i, j + 1], [i, j - 1]]:
		if 0 <= ni < n and 0 <= nj < m and ((ni, nj) not in vis) and (g[ni][nj] != '#'):
			yield dfs(ni, nj)
	yield None
t = N()
for i in range(t):
	(n, m) = RL()
	g = []
	for i in range(n):
		g.append(list(input()))
	f = 1
	c = 0
	for i in range(n):
		for j in range(m):
			if g[i][j] == 'B':
				for (ni, nj) in [[i + 1, j], [i - 1, j], [i, j + 1], [i, j - 1]]:
					if 0 <= ni < n and 0 <= nj < m:
						if g[ni][nj] == 'G':
							f = 0
							break
						elif g[ni][nj] == '.':
							g[ni][nj] = '#'
				if not f:
					break
			elif g[i][j] == 'G':
				c += 1
		if not f:
			break
	if f:
		if g[n - 1][m - 1] == '#':
			if c:
				f = 0
		else:
			vis = set()
			dfs(n - 1, m - 1)
			if c != 0:
				f = 0
	ans = 'Yes' if f else 'No'
	print(ans)


def num_good_guys(grid, n, m):
	res = 0
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 'G':
				res += 1
	return res

def add_neightbor_wall(grid, i, j, n, m):
	if i >= 0 and i < n and (j >= 0) and (j < m):
		if grid[i][j] == 'G':
			return False
		if grid[i][j] == '.':
			grid[i][j] = '#'
	return True

def add_neightbor_walls(grid, i, j, n, m):
	if not add_neightbor_wall(grid, i - 1, j, n, m):
		return False
	if not add_neightbor_wall(grid, i, j - 1, n, m):
		return False
	if not add_neightbor_wall(grid, i + 1, j, n, m):
		return False
	if not add_neightbor_wall(grid, i, j + 1, n, m):
		return False
	return True

def solve_test_case(t):
	(n, m) = parse_array(int)
	grid = [list(input()) for _ in range(n)]
	n_good_guy = num_good_guys(grid, n, m)
	if n_good_guy == 0:
		print('Yes')
		return
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 'B':
				if not add_neightbor_walls(grid, i, j, n, m):
					print('No')
					return
	if grid[n - 1][m - 1] == '#':
		print('No')
		return
	reached_good_guys = 0
	queue = [(n - 1, m - 1)]
	visited = set()
	while len(queue) > 0:
		(i, j) = queue.pop(0)
		if i >= 0 and i < n and (j >= 0) and (j < m) and ((i, j) not in visited) and (grid[i][j] in ['.', 'G']):
			visited.add((i, j))
			if grid[i][j] == 'G':
				reached_good_guys += 1
			queue.append((i + 1, j))
			queue.append((i, j + 1))
			queue.append((i - 1, j))
			queue.append((i, j - 1))
	if reached_good_guys == n_good_guy:
		print('Yes')
	else:
		print('No')

def parse_array(f):
	return list(map(f, input().split()))

def solve():
	T = int(input())
	for t in range(T):
		solve_test_case(t)
solve()


from collections import deque
import sys
input = sys.stdin.readline

def bounds(x, y, n, m):
	return 0 <= x < n and 0 <= y < m
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	grid = []
	for i in range(n):
		grid.append(list(input().strip()))
	dirs = [[1, 0], [-1, 0], [0, -1], [0, 1]]
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 'B':
				for (a, b) in dirs:
					i2 = i + a
					j2 = j + b
					if bounds(i2, j2, n, m) and grid[i2][j2] != 'G' and (grid[i2][j2] != 'B'):
						grid[i2][j2] = '#'
	visited = [[0 for i in range(m)] for j in range(n)]
	dq = deque([[n - 1, m - 1]])
	while dq:
		(x, y) = dq.popleft()
		visited[x][y] = 1
		if grid[x][y] == '#':
			continue
		for (a, b) in dirs:
			nx = x + a
			ny = y + b
			if bounds(nx, ny, n, m) and (not visited[nx][ny]) and (grid[nx][ny] != '#'):
				visited[nx][ny] = 1
				dq.append([nx, ny])
	bad = False
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 'G' and (not visited[i][j]):
				bad = True
			elif grid[i][j] == 'B' and visited[i][j]:
				bad = True
	if bad:
		print('No')
	else:
		print('Yes')


from sys import stdin, stdout
from math import *
from heapq import *
from collections import *
a = []

def main():
	ntest = int(stdin.readline())
	for testcase in range(ntest):
		(n, m) = [int(k) for k in stdin.readline().split()]
		a = []
		for i in range(n + 2):
			if i <= 0 or i > n:
				a.append(['#'] * (m + 2))
			else:
				a.append(list('#' + stdin.readline().strip() + '#'))
		succ = True
		goodp = 0
		for i in range(1, 1 + n):
			for j in range(1, 1 + m):
				if a[i][j] == 'G':
					goodp += 1
				if a[i][j] == 'B':
					for (r, c) in [[i - 1, j], [i, j - 1], [i + 1, j], [i, j + 1]]:
						if a[r][c] == 'B':
							continue
						if a[r][c] == 'G':
							succ = False
							continue
						if a[r][c] == '.':
							if r == n and c == m:
								succ = False
							a[r][c] = '#'
		if goodp == 0:
			stdout.write('Yes\n')
			continue
		q = [(n, m)]
		resc = 0
		i = 0
		while i < len(q):
			(r, c) = q[i]
			for (u, v) in [(r - 1, c), (r, c - 1), (r + 1, c), (r, c + 1)]:
				if a[u][v] == 'G':
					resc += 1
				if a[u][v] != '#':
					a[u][v] = '#'
					q.append((u, v))
			i += 1
		if succ and resc >= goodp:
			stdout.write('Yes\n')
		else:
			stdout.write('No\n')
	return 0
main()


from sys import stdin
from collections import deque

def fun():
	(n, m) = map(int, stdin.readline().split())
	lst = [list(stdin.readline()) for _ in range(n)]
	good = []
	for x in range(n):
		for y in range(m):
			if lst[x][y] == 'B':
				if x != 0:
					if lst[x - 1][y] == 'G':
						print('No')
						return
					elif lst[x - 1][y] == '.':
						lst[x - 1][y] = '#'
				if x != n - 1:
					if lst[x + 1][y] == 'G':
						print('No')
						return
					elif lst[x + 1][y] == '.':
						lst[x + 1][y] = '#'
				if y != 0:
					if lst[x][y - 1] == 'G':
						print('No')
						return
					elif lst[x][y - 1] == '.':
						lst[x][y - 1] = '#'
				if y != m - 1:
					if lst[x][y + 1] == 'G':
						print('No')
						return
					elif lst[x][y + 1] == '.':
						lst[x][y + 1] = '#'
			elif lst[x][y] == 'G':
				good.append((x, y))
	if lst[n - 1][m - 1] == 'B':
		print('No')
		return
	done = set()
	for r in good:
		if r in done:
			continue
		curr = deque([r])
		visi = {r}
		done.add(r)
		fl = 0
		while len(curr):
			x = curr.popleft()
			if x[0] != 0 and (x[0] - 1, x[1]) not in visi and (lst[x[0] - 1][x[1]] == '.') or (x[0] != 0 and (x[0] - 1, x[1]) not in visi and (lst[x[0] - 1][x[1]] == 'G')):
				curr.append((x[0] - 1, x[1]))
				visi.add((x[0] - 1, x[1]))
				if lst[x[0] - 1][x[1]] == 'G':
					done.add((x[0] - 1, x[1]))
			if x[0] != n - 1 and (x[0] + 1, x[1]) not in visi and (lst[x[0] + 1][x[1]] == '.') or (x[0] != n - 1 and (x[0] + 1, x[1]) not in visi and (lst[x[0] + 1][x[1]] == 'G')):
				curr.append((x[0] + 1, x[1]))
				visi.add((x[0] + 1, x[1]))
				if lst[x[0] + 1][x[1]] == 'G':
					done.add((x[0] + 1, x[1]))
			if x[1] != 0 and (x[0], x[1] - 1) not in visi and (lst[x[0]][x[1] - 1] == '.') or (x[1] != 0 and (x[0], x[1] - 1) not in visi and (lst[x[0]][x[1] - 1] == 'G')):
				curr.append((x[0], x[1] - 1))
				visi.add((x[0], x[1] - 1))
				if lst[x[0]][x[1] - 1] == 'G':
					done.add((x[0], x[1] - 1))
			if x[1] != m - 1 and (x[0], x[1] + 1) not in visi and (lst[x[0]][x[1] + 1] == '.') or (x[1] != m - 1 and (x[0], x[1] + 1) not in visi and (lst[x[0]][x[1] + 1] == 'G')):
				curr.append((x[0], x[1] + 1))
				visi.add((x[0], x[1] + 1))
				if lst[x[0]][x[1] + 1] == 'G':
					done.add((x[0], x[1] + 1))
			if (n - 1, m - 1) in visi:
				fl = 1
				break
		if not fl:
			print('No')
			return
	print('Yes')
for _ in range(int(stdin.readline())):
	fun()


def solve(n, m, z):
	for row in range(0, n + 2):
		for col in range(1, m + 1):
			if z[row][col] == 'B':
				for (h, v) in [[0, 1], [0, -1], [1, 0], [-1, 0]]:
					who = z[row + v][col + h]
					if who == 'G':
						return False
					if who == '.':
						z[row + v][col + h] = '#'
	gexists = False
	for x in z:
		if 'G' in x:
			gexists = True
	if not gexists:
		return True
	walk1(z, n, m)
	for x in z:
		if 'G' in x:
			return False
	return True

def p(z):
	return
	print()
	[print(''.join(x)) for x in z]

def walk1(z, n, m):
	l = list([[n, m]])
	while l:
		[x, y] = l.pop()
		if z[x][y] in '.G':
			p(z)
			z[x][y] = ' '
			new = [[x + h, y + v] for (h, v) in [[0, 1], [0, -1], [1, 0], [-1, 0]]]
			l += new

def walk(z, x, y):
	if z[x][y] in '# ':
		return
	p(z)
	z[x][y] = ' '
	for (h, v) in [[0, 1], [0, -1], [1, 0], [-1, 0]]:
		if z[x + v][y + h] in 'G.':
			walk(z, x + v, y + h)

def main():
	for _ in range(int(input())):
		z = list()
		(n, m) = [int(x) for x in input().split()]
		w = '#' * (m + 2)
		z = [w] + ['#' + input() + '#' for _ in range(n)] + [w]
		z = [list(x) for x in z]
		p(z)
		res = solve(n, m, z)
		if res:
			print('Yes')
		else:
			print('No')
		p(z)
main()


from collections import deque
from sys import stdin, stdout
import math
input = stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = [list(input().strip()) for i in range(n)]
	good = []
	bad = []
	for i in range(n):
		for g in range(m):
			if arr[i][g] == 'G':
				good.append((i, g))
			elif arr[i][g] == 'B':
				bad.append((i, g))
	dirs = [(1, 0), (-1, 0), (0, 1), (0, -1)]
	can = True
	for i in bad:
		for g in dirs:
			newx = i[0] + g[0]
			newy = i[1] + g[1]
			if not (0 <= newx < n and 0 <= newy < m):
				continue
			if arr[newx][newy] == 'G':
				can = False
			if arr[newx][newy] == '.':
				arr[newx][newy] = '#'
	visited = [[0 for g in range(m)] for i in range(n)]
	buff = deque()
	if arr[n - 1][m - 1] != '#':
		visited[n - 1][m - 1] = 1
		buff = deque([(n - 1, m - 1)])
	while len(buff):
		i = buff.popleft()
		for g in dirs:
			newx = i[0] + g[0]
			newy = i[1] + g[1]
			if not (0 <= newx < n and 0 <= newy < m) or visited[newx][newy] or arr[newx][newy] == '#':
				continue
			visited[newx][newy] = 1
			buff.append((newx, newy))
	for i in good:
		if not visited[i[0]][i[1]]:
			can = False
	for i in bad:
		if visited[i[0]][i[1]]:
			can = False
	print('Yes' if can else 'No')


from bisect import bisect_right
import sys
sys.setrecursionlimit(10000)

def findPossible(start):
	theno = start[1] + start[0] * m
	possible[theno] = True
	if visited[theno] is True:
		return
	visited[theno] = True
	if start[0] != 0 and a[start[0] - 1][start[1]] != '#':
		findPossible([start[0] - 1, start[1]])
	if start[1] != 0 and a[start[0]][start[1] - 1] != '#':
		findPossible([start[0], start[1] - 1])
	if start[0] != n - 1 and a[start[0] + 1][start[1]] != '#':
		findPossible([start[0] + 1, start[1]])
	if start[1] != m - 1 and a[start[0]][start[1] + 1] != '#':
		findPossible([start[0], start[1] + 1])
t = int(input())
for _ in range(t):
	try:
		(n, m) = input().split()
		n = int(n)
		m = int(m)
		a = []
		G = []
		B = []
		for i in range(n):
			b = input()
			a.append(list(b))
			for j in range(len(b)):
				if b[j] == 'G':
					G.append([i, j])
				if b[j] == 'B':
					B.append([i, j])
		for point in B:
			if point[0] != 0:
				a[point[0] - 1][point[1]] = '#'
			if point[1] != 0:
				a[point[0]][point[1] - 1] = '#'
			if point[0] != n - 1:
				a[point[0] + 1][point[1]] = '#'
			if point[1] != m - 1:
				a[point[0]][point[1] + 1] = '#'
		possible = [False] * (n * m)
		visited = [False] * (n * m)
		start = [n - 1, m - 1]
		if a[n - 1][m - 1] == '#':
			if len(G) == 0:
				print('Yes')
			else:
				print('No')
		else:
			findPossible(start)
			sed = 0
			for good in G:
				theno = good[1] + good[0] * m
				if possible[theno] is False:
					sed = 1
					break
			if sed == 0:
				print('Yes')
			else:
				print('No')
	except Exception as e:
		print(str(e))


x = [1, -1, 0, 0]
y = [0, 0, 1, -1]

def bfs(arr, visited, n, m, e_x, e_y):
	q = []
	if arr[n][m] != '#':
		visited[n][m] = True
		q.append([n, m])
	while len(q) != 0:
		ele = q.pop(0)
		a = ele[0]
		b = ele[1]
		for k in range(4):
			na = a + x[k]
			nb = b + y[k]
			if na >= 0 and na < e_x and (nb >= 0) and (nb < e_y):
				if visited[na][nb] == False and arr[na][nb] != '#':
					visited[na][nb] = True
					q.append([na, nb])
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	ans = 'Yes'
	for i in range(n):
		temp = list(input())
		arr.append(temp)
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'B':
				for k in range(4):
					pos_x = i + x[k]
					pos_y = j + y[k]
					if pos_x >= 0 and pos_x < n and (pos_y >= 0) and (pos_y < m):
						if arr[pos_x][pos_y] == 'G':
							ans = 'NO'
						elif arr[pos_x][pos_y] == '.':
							arr[pos_x][pos_y] = '#'
	visited = [[False] * m for i in range(n)]
	bfs(arr, visited, n - 1, m - 1, n, m)
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'G' and visited[i][j] == False:
				ans = 'NO'
				break
	print(ans)


def isValid(x, y, n, m):
	if x < 0 or x > n - 1 or y < 0 or (y > m - 1):
		return False
	if vis[x][y] == 1 or matrix[x][y] == '#':
		return False
	return True
dx = [-1, 0, 1, 0]
dy = [0, 1, 0, -1]

def dfs(x, y, n, m):
	stack = [[x, y]]
	vis[x][y] = 1
	while stack:
		temp = stack.pop()
		curX = temp[0]
		curY = temp[1]
		for i in range(4):
			if isValid(curX + dx[i], curY + dy[i], n, m):
				newX = curX + dx[i]
				newY = curY + dy[i]
				vis[newX][newY] = 1
				stack.append([newX, newY])
t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	matrix = []
	c = 0
	for i in range(n):
		s = str(input())
		lis = []
		for j in range(m):
			lis.append(s[j])
		c += lis.count('G')
		matrix.append(lis)
	a = 0
	vis = [[0] * m for i in range(n)]
	for i in range(n):
		for j in range(m):
			if matrix[i][j] == 'B':
				for k in range(4):
					if isValid(i + dx[k], j + dy[k], n, m):
						if matrix[i + dx[k]][j + dy[k]] == 'G' or (i + dx[k] == n - 1 and j + dy[k] == m - 1):
							a += 1
						elif matrix[i + dx[k]][j + dy[k]] == '.':
							matrix[i + dx[k]][j + dy[k]] = '#'
	if c == 0:
		print('YES')
	elif a > 0:
		print('NO')
	else:
		b = 0
		for i in range(n):
			for j in range(m):
				if vis[i][j] == 0 and matrix[i][j] == 'G':
					dfs(i, j, n, m)
					b += 1
		if b == 1 and vis[-1][-1] == 1 or b == 0:
			print('YES')
		else:
			print('NO')


from collections import defaultdict as dd
import math
import sys
import heapq
import copy
input = sys.stdin.readline

def nn():
	return int(input())

def li():
	return list(input())

def mi():
	return map(int, input().split())

def lm():
	return list(map(int, input().split()))
q = nn()
for _ in range(q):
	(n, m) = mi()
	maze = []
	for i in range(n):
		row = li()
		maze.append(row)
	bad = False
	goods = []
	for i in range(n):
		for j in range(m):
			if maze[i][j] == 'G':
				goods.append((i, j))
			if maze[i][j] == 'B':
				for r in (-1, 0, 1):
					for c in (-1, 0, 1):
						if r == 0 or c == 0:
							if 0 <= i + r and i + r < n:
								if 0 <= j + c and j + c < m:
									if maze[i + r][j + c] == 'G':
										bad = True
									if maze[i + r][j + c] == '.':
										maze[i + r][j + c] = '#'
	safes = set()
	safes.add((n - 1, m - 1))
	bads = set()
	for good in goods:
		visited = set()
		s = [good]
		found = False
		while s:
			(i, j) = s.pop()
			visited.add((i, j))
			if (i, j) in safes:
				for el in visited:
					safes.add(el)
				found = True
				break
			for r in (-1, 0, 1):
				for c in (-1, 0, 1):
					if 0 <= i + r and i + r < n:
						if 0 <= j + c and j + c < m:
							if r == 0 or c == 0:
								if maze[i + r][j + c] == '.' or maze[i + r][j + c] == 'G':
									if (i + r, j + c) not in visited:
										s.append((i + r, j + c))
		if not found:
			bad = True
			break
	if bad:
		print('NO')
	else:
		print('YES')


def neighbors(position, rows, cols):
	(r, c) = position
	neighbors = []
	for candidate in [(r - 1, c), (r + 1, c), (r, c - 1), (r, c + 1)]:
		(new_r, new_c) = candidate
		if new_r < 0 or new_r >= rows or new_c < 0 or (new_c >= cols):
			continue
		else:
			neighbors.append(candidate)
	return neighbors

def check_maze(rows, cols, maze, good_person_positions, bad_person_positions):
	for b in bad_person_positions:
		for neighbor in neighbors(b, rows, cols):
			(r, c) = neighbor
			if neighbor in good_person_positions:
				return 'NO'
			if maze[r][c] == '.':
				maze[r][c] = '#'
	if len(good_person_positions) > 0 and maze[rows - 1][cols - 1] == '#':
		return 'NO'
	queue = [(rows - 1, cols - 1)]
	visited = {}
	while len(queue) > 0 and len(good_person_positions) > 0:
		curr_position = queue.pop()
		if curr_position in visited:
			continue
		visited[curr_position] = 1
		if curr_position in good_person_positions:
			good_person_positions.remove(curr_position)
		(r, c) = curr_position
		if maze[r][c] == '#':
			continue
		queue += neighbors(curr_position, rows, cols)
	if len(good_person_positions) == 0:
		return 'YES'
	else:
		return 'NO'
T = int(input())
for _ in range(T):
	(n, m) = map(int, input().strip().split())
	(good_person_positions, bad_person_positions) = (set(), set())
	maze = []
	for r in range(n):
		row = list(input().strip())
		for (c, elem) in enumerate(row):
			if elem == 'G':
				good_person_positions.add((r, c))
			elif elem == 'B':
				bad_person_positions.add((r, c))
		maze.append(row)
	print(check_maze(n, m, maze, good_person_positions, bad_person_positions))


import sys
input = sys.stdin.readline

def isvalid(i, j):
	if 0 <= i < n and 0 <= j < m:
		return True
	else:
		return False

def dfs(i, j):
	st = [(i, j)]
	while st:
		(i, j) = st.pop()
		if vis[i][j] == 1 or w[i][j] == 1:
			continue
		vis[i][j] = 1
		if isvalid(i - 1, j):
			st.append((i - 1, j))
		if isvalid(i, j - 1):
			st.append((i, j - 1))
		if isvalid(i + 1, j):
			st.append((i + 1, j))
		if isvalid(i, j + 1):
			st.append((i, j + 1))
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	g = []
	w = [[0 for j in range(m)] for i in range(n)]
	vis = [[0 for j in range(m)] for i in range(n)]
	for i in range(n):
		g.append(input())
	for i in range(n):
		for j in range(m):
			if g[i][j] == 'B':
				if isvalid(i - 1, j):
					w[i - 1][j] = 1
				if isvalid(i, j - 1):
					w[i][j - 1] = 1
				if isvalid(i + 1, j):
					w[i + 1][j] = 1
				if isvalid(i, j + 1):
					w[i][j + 1] = 1
			elif g[i][j] == '#':
				w[i][j] = 1
	dfs(n - 1, m - 1)
	f = 0
	for i in range(n):
		for j in range(m):
			if g[i][j] == 'G' and vis[i][j] == 0:
				f = 1
				break
		if f:
			break
	if f:
		print('No')
	else:
		print('Yes')


def DFS(maze, good):
	n = len(maze)
	m = len(maze[0])
	stack = [(n - 1, m - 1)]
	directions = [[-1, 0], [1, 0], [0, -1], [0, 1]]
	maze[-1][-1] = '#'
	visited_good = set()
	while stack:
		position = stack.pop()
		blocked = False
		new_positions = []
		new_good = []
		for direction in directions:
			if 0 <= position[0] + direction[0] < n and 0 <= position[1] + direction[1] < m:
				if maze[position[0] + direction[0]][position[1] + direction[1]] == 'G':
					new_positions.append((position[0] + direction[0], position[1] + direction[1]))
					new_good.append((position[0] + direction[0], position[1] + direction[1]))
				elif maze[position[0] + direction[0]][position[1] + direction[1]] == '.':
					new_positions.append((position[0] + direction[0], position[1] + direction[1]))
				elif maze[position[0] + direction[0]][position[1] + direction[1]] == 'B':
					if maze[position[0]][position[1]] == 'G':
						print('NO')
						return
					blocked = True
		maze[position[0]][position[1]] = '#'
		if not blocked:
			stack.extend(new_positions)
			for g in new_good:
				visited_good.add(g)
	if len(visited_good) == good:
		print('YES')
	else:
		print('NO')
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	maze = [[c for c in input()] for _ in range(n)]
	good = 0
	for row in maze:
		for x in row:
			if x == 'G':
				good += 1
	DFS(maze, good)


from sys import stdin, stdout
import sys
sys.setrecursionlimit(100000)

def block(mtr, taken_care_of, x, y, n, m):
	taken_care_of[y][x] = True
	for (row_offset, col_offset) in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
		if y + row_offset >= 0 and y + row_offset < n and (x + col_offset < m) and (x + col_offset >= 0):
			if mtr[y + row_offset][x + col_offset] == '.':
				mtr[y + row_offset][x + col_offset] = '#'
			if mtr[y + row_offset][x + col_offset] == 'B' and (not taken_care_of[y + row_offset][x + col_offset]):
				block(mtr, taken_care_of, x + col_offset, y + row_offset, n, m)
t = int(stdin.readline().strip())
for _ in range(t):
	(n, m) = stdin.readline().strip().split(' ')
	(n, m) = (int(n), int(m))
	mtr = []
	for i in range(n):
		mtr.append(list(stdin.readline().strip()))
	taken_care_of = [[False for i in range(m)] for j in range(n)]
	for i in range(n):
		for j in range(m):
			if not taken_care_of[i][j] and mtr[i][j] == 'B':
				block(mtr, taken_care_of, j, i, n, m)
	can_reach = [[False for i in range(m)] for j in range(n)]
	queue = []
	if mtr[n - 1][m - 1] != '#':
		queue.append((n - 1, m - 1))
		can_reach[n - 1][m - 1] = True
	else:
		can_reach[n - 1][m - 1] = False
	while len(queue) > 0:
		(y, x) = queue.pop(-1)
		for (row_offset, col_offset) in [(0, 1), (0, -1), (1, 0), (-1, 0)]:
			if y + row_offset >= 0 and y + row_offset < n and (x + col_offset < m) and (x + col_offset >= 0) and (mtr[y + row_offset][x + col_offset] != '#') and (not can_reach[y + row_offset][x + col_offset]):
				queue.append((y + row_offset, x + col_offset))
				can_reach[y + row_offset][x + col_offset] = True
	ans = True
	for i in range(n):
		for j in range(m):
			if mtr[i][j] == 'B' and can_reach[i][j] == True or (mtr[i][j] == 'G' and can_reach[i][j] == False):
				ans = False
	if ans:
		stdout.write('Yes\n')
	else:
		stdout.write('No\n')


import sys
from collections import deque

def input():
	return sys.stdin.readline()[:-1]

def main():
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		G = [['#'] + [s for s in input()] + ['#'] for k in range(n)]
		G = [['#'] * (m + 2)] + G + [['#'] * (m + 2)]
		flag = 0
		dx = [1, 0, -1, 0]
		dy = [0, 1, 0, -1]
		start = []
		for y in range(1, n + 1):
			for x in range(1, m + 1):
				if G[y][x] == 'B':
					for k in range(4):
						if G[y + dy[k]][x + dx[k]] == 'G':
							flag = 1
							break
						elif G[y + dy[k]][x + dx[k]] == '.':
							G[y + dy[k]][x + dx[k]] = '#'
				elif G[y][x] == 'G':
					start.append([y, x, 0])
		if len(start) == 0:
			flag = 0
		elif G[n][m] == '#':
			flag = 1
		else:
			dist = [[10 ** 9] * (m + 2) for k in range(n + 2)]
			Q = deque([[n, m, 0]])
			dist[n][m] = 0
			while len(Q) > 0:
				ima = Q.popleft()
				for k in range(4):
					if G[ima[0] + dy[k]][ima[1] + dx[k]] == '.' or G[ima[0] + dy[k]][ima[1] + dx[k]] == 'G':
						if dist[ima[0] + dy[k]][ima[1] + dx[k]] > ima[2] + 1:
							dist[ima[0] + dy[k]][ima[1] + dx[k]] = ima[2] + 1
							Q.append([ima[0] + dy[k], ima[1] + dx[k], ima[2] + 1])
			for e in start:
				if dist[e[0]][e[1]] == 10 ** 9:
					flag = 1
					break
		print('No' if flag == 1 else 'Yes')
main()


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().strip().split()))
	matrix = []
	for _ in range(n):
		matrix.append(list(input().strip()))
	cant = False
	for i in range(n):
		for j in range(m):
			if matrix[i][j] == 'B':
				if i > 0:
					if matrix[i - 1][j] == 'G':
						cant = True
					elif matrix[i - 1][j] != 'B':
						matrix[i - 1][j] = '#'
				if j > 0:
					if matrix[i][j - 1] == 'G':
						cant = True
					elif matrix[i][j - 1] != 'B':
						matrix[i][j - 1] = '#'
				if i < n - 1:
					if matrix[i + 1][j] == 'G':
						cant = True
					elif matrix[i + 1][j] != 'B':
						matrix[i + 1][j] = '#'
				if j < m - 1:
					if matrix[i][j + 1] == 'G':
						cant = True
					elif matrix[i][j + 1] != 'B':
						matrix[i][j + 1] = '#'
	tags = [[False] * m for _ in range(n)]
	todo = [(n - 1, m - 1)]
	while len(todo) > 0:
		newtodo = []
		for (a, b) in todo:
			if tags[a][b] or matrix[a][b] == '#':
				continue
			tags[a][b] = True
			if a > 0:
				newtodo.append((a - 1, b))
			if b > 0:
				newtodo.append((a, b - 1))
			if a < n - 1:
				newtodo.append((a + 1, b))
			if b < m - 1:
				newtodo.append((a, b + 1))
		todo = newtodo
	for i in range(n):
		for j in range(m):
			if matrix[i][j] == 'G' and tags[i][j] is False:
				cant = True
	if cant:
		print('No')
	else:
		print('Yes')


T = int(input())
for _ in range(0, T):
	(n, m) = map(int, input().split())
	L = []
	vis = []
	org = 0
	for i in range(n):
		s = input()
		h = []
		h2 = []
		for j in range(0, len(s)):
			if s[j] == 'G':
				org += 1
			h.append(s[j])
			h2.append(False)
		L.append(h)
		vis.append(h2)
	temp = 0
	for i in range(n):
		for j in range(m):
			if L[i][j] == 'B':
				L[i][j] = '#'
				if i - 1 >= 0:
					if L[i - 1][j] == 'G':
						temp = 1
						break
					elif L[i - 1][j] == '.':
						L[i - 1][j] = '#'
				if i + 1 < n:
					if L[i + 1][j] == 'G':
						temp = 1
						break
					elif L[i + 1][j] == '.':
						L[i + 1][j] = '#'
				if j - 1 >= 0:
					if L[i][j - 1] == 'G':
						temp = 1
						break
					elif L[i][j - 1] == '.':
						L[i][j - 1] = '#'
				if j + 1 < m:
					if L[i][j + 1] == 'G':
						temp = 1
						break
					elif L[i][j + 1] == '.':
						L[i][j + 1] = '#'
		if temp == 1:
			break
	if temp == 1 or (L[n - 1][m - 1] == '#' and org > 0):
		print('No')
	else:
		global ct
		ct = 0

		def dfs(i, j):
			if L[i][j] == 'G':
				global ct
				ct += 1
			if i - 1 >= 0:
				if L[i - 1][j] != '#' and vis[i - 1][j] == False:
					vis[i - 1][j] = True
					dfs(i - 1, j)
			if i + 1 < n:
				if L[i + 1][j] != '#' and vis[i + 1][j] == False:
					vis[i + 1][j] = True
					dfs(i + 1, j)
			if j - 1 >= 0:
				if L[i][j - 1] != '#' and vis[i][j - 1] == False:
					vis[i][j - 1] = True
					dfs(i, j - 1)
			if j + 1 < m:
				if L[i][j + 1] != '#' and vis[i][j + 1] == False:
					vis[i][j + 1] = True
					dfs(i, j + 1)
		vis[n - 1][m - 1] = True
		dfs(n - 1, m - 1)
		if ct == org:
			print('Yes')
		else:
			print('No')


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()))
	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')


import sys
sys.setrecursionlimit(int(pow(10, 6)))

def get_neighbors(grid, i, j):
	lst = []
	if i > 0:
		lst.append((i - 1, j))
	if i < len(grid) - 1:
		lst.append((i + 1, j))
	if j > 0:
		lst.append((i, j - 1))
	if j < len(grid[0]) - 1:
		lst.append((i, j + 1))
	return lst

def solve():
	T = int(input())
	for _ in range(T):
		(n, m) = [int(s) for s in input().split(' ')]
		grid = []
		for _ in range(n):
			grid.append(list(input()))
		count = 0
		for i in range(len(grid)):
			for j in range(len(grid[0])):
				if grid[i][j] == 'G':
					count += 1
				elif grid[i][j] == 'B':
					for neighbor in get_neighbors(grid, i, j):
						if grid[neighbor[0]][neighbor[1]] == '.':
							grid[neighbor[0]][neighbor[1]] = '#'
		curr = (len(grid) - 1, len(grid[0]) - 1)
		if count == 0:
			print('Yes')
		elif grid[curr[0]][curr[1]] == '#' or grid[curr[0]][curr[1]] == 'B':
			print('No')
		else:
			ct = dfs(grid, curr)
			if ct == count:
				print('Yes')
			else:
				print('No')

def dfs(grid, curr):
	count = 0
	if grid[curr[0]][curr[1]] == 'G':
		count += 1
	if grid[curr[0]][curr[1]] == 'B':
		return -1000000
	grid[curr[0]][curr[1]] = '#'
	for n in get_neighbors(grid, curr[0], curr[1]):
		if grid[n[0]][n[1]] != '#':
			count += dfs(grid, n)
	return count
solve()


from fractions import Fraction
import bisect
import os
from collections import Counter
import bisect
from collections import defaultdict
import math
import random
import heapq as hq
from math import sqrt
import sys
from functools import reduce, cmp_to_key
from collections import deque
import threading
from itertools import combinations
from io import BytesIO, IOBase
from itertools import accumulate
from queue import Queue
sys.setrecursionlimit(200000)

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def tinput():
	return input().split()

def rinput():
	return map(int, tinput())

def rlinput():
	return list(rinput())
mod = int(1000000000.0) + 7

def factors(n):
	return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))
t = iinput()
for i in range(t):
	(n, m) = rinput()
	mat = []
	for i in range(n):
		mat.append(list(input()))
	flg = False
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 'B':
				if i > 0:
					if mat[i - 1][j] in ['.', '#']:
						mat[i - 1][j] = '#'
					elif mat[i - 1][j] == 'G':
						flg = True
						break
				if i < n - 1:
					if mat[i + 1][j] in ['.', '#']:
						mat[i + 1][j] = '#'
					elif mat[i + 1][j] == 'G':
						flg = True
						break
				if j > 0:
					if mat[i][j - 1] in ['.', '#']:
						mat[i][j - 1] = '#'
					elif mat[i][j - 1] == 'G':
						flg = True
						break
				if j < m - 1:
					if mat[i][j + 1] in ['.', '#']:
						mat[i][j + 1] = '#'
					elif mat[i][j + 1] == 'G':
						flg = True
						break
		if flg:
			break
	if flg:
		print('No')
		continue

	def recur(i, j):
		if i < 0 or j < 0 or i > n - 1 or (j > m - 1):
			return
		if mat[i][j] in ['B', '#'] or visited[i][j]:
			return
		visited[i][j] = True
		if i > 0:
			recur(i - 1, j)
		if i < n - 1:
			recur(i + 1, j)
		if j < m - 1:
			recur(i, j + 1)
		if j > 0:
			recur(i, j - 1)
	visited = [[False] * m for i in range(n)]
	recur(n - 1, m - 1)
	for i in range(n):
		for j in range(m):
			if mat[i][j] == 'G' and (not visited[i][j]):
				flg = True
				break
		if flg:
			break
	print(['Yes', 'No'][flg])


import sys
ip = lambda : sys.stdin.readline().rstrip()
from collections import deque as dq

def f(src, isv):
	goods = dq([src])
	fl = False
	while goods:
		(x, y) = goods.popleft()
		if isv[x][y]:
			continue
		if x == n - 1 and y == m - 1:
			fl = True
			continue
		isv[x][y] = True
		for (d, e) in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
			(nx, ny) = (x + d, y + e)
			tp = [nx, ny]
			if c(nx, ny) and (not isv[nx][ny]):
				if not blocked[nx][ny] and a[nx][ny] != '#':
					goods.append(tp)
	return fl
for _ in range(int(ip())):
	(n, m) = map(int, ip().split())
	a = [list(ip()) for _ in range(n)]
	c = lambda x, y: x >= 0 and x < n and (y >= 0) and (y < m)
	blocked = [[False for _ in range(m)] for _ in range(n)]
	(ans, found) = (True, False)
	isv = [[False for _ in range(m)] for _ in range(n)]
	(bads, goods) = (dq(), dq())
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'B':
				bads.append([i, j])
			if a[i][j] == 'G':
				found = True
				goods.append([i, j])
	if not found:
		print('yes')
		continue
	fl = False
	while bads:
		(x, y) = bads.popleft()
		if x == n - 1 and y == m - 1:
			fl = True
			break
		isv[x][y] = True
		if blocked[x][y] or a[x][y] == '#':
			continue
		if a[x][y] == 'G':
			fl = True
			break
		if a[x][y] == '.':
			blocked[x][y] = True
			continue
		for (d, e) in [[1, 0], [0, 1], [-1, 0], [0, -1]]:
			(nx, ny) = (x + d, y + e)
			tp = [nx, ny]
			if c(nx, ny) and (not isv[nx][ny]):
				bads.append(tp)
	if fl:
		print('no')
		continue
	ans = True
	for i in goods:
		if not isv[i[0]][i[1]]:
			if not f(i, isv):
				ans = False
				break
	print('yes' if ans else 'no')


from collections import deque
T = int(input())

def ans(maze):
	N = len(maze)
	M = len(maze[0])
	has_g = 'G' in ''.join((''.join(row) for row in maze))
	for x in range(N):
		for y in range(M):
			if maze[x][y] != 'B':
				continue
			for (dy, dx) in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
				(new_x, new_y) = (x + dx, y + dy)
				if not 0 <= new_x < N:
					continue
				if not 0 <= new_y < M:
					continue
				if maze[new_x][new_y] == 'G':
					return 'No'
				elif maze[new_x][new_y] in ['B', '#']:
					continue
				elif maze[new_x][new_y] == '.':
					maze[new_x][new_y] = '#'
				else:
					assert False
	if not has_g:
		return 'Yes'
	if maze[N - 1][M - 1] == '#':
		return 'No'
	frontier = deque([(N - 1, M - 1)])
	while len(frontier):
		(x, y) = frontier.popleft()
		for (dy, dx) in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
			(new_x, new_y) = (x + dx, y + dy)
			if not 0 <= new_x < N:
				continue
			if not 0 <= new_y < M:
				continue
			if maze[new_x][new_y] in ['r', '#']:
				continue
			elif maze[new_x][new_y] in ['G', '.']:
				maze[new_x][new_y] = 'r'
				frontier.append((new_x, new_y))
			else:
				assert False
	has_g = 'G' in ''.join((''.join(row) for row in maze))
	if has_g:
		return 'No'
	return 'Yes'
for t in range(T):
	(N, M) = input().split(' ')
	N = int(N)
	maze = []
	for _ in range(N):
		row = input()
		maze += [list(row)]
	print(ans(maze))


from collections import defaultdict
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().strip().split())
	arr = []
	for _ in range(n):
		arr.append(list(input()))
	G = set()
	f = 0
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'G':
				G.add((i, j))
			elif arr[i][j] == 'B':
				for (x, y) in [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]]:
					if 0 <= x < n and 0 <= y < m and (arr[x][y] != 'B'):
						if arr[x][y] == 'G':
							f = 1
							break
						arr[x][y] = '#'
	if f:
		print('No')
	elif arr[-1][-1] == '#':
		if G:
			print('No')
		else:
			print('Yes')
	else:
		visited = [[False for _ in range(m)] for _ in range(n)]
		visited[n - 1][m - 1] = True
		queue = [(n - 1, m - 1)]
		while queue:
			(i, j) = queue.pop()
			G.discard((i, j))
			for (x, y) in [[i - 1, j], [i + 1, j], [i, j - 1], [i, j + 1]]:
				if 0 <= x < n and 0 <= y < m and (not visited[x][y]) and (arr[x][y] != '#'):
					visited[x][y] = True
					queue.append((x, y))
		if not G:
			print('Yes')
		else:
			print('No')


from sys import setrecursionlimit as srl
srl(10 ** 5)
DIR = [(-1, 0), (1, 0), (0, -1), (0, 1)]
WALL = '#'
GOOD_PERSON = 'G'
BAD_PERSON = 'B'

def dfs(i, j):
	if i > n or i == 0 or j > m or (j == 0):
		return
	been[i][j] = 1
	for (d_i, d_j) in DIR:
		if not been[i + d_i][j + d_j] and a[i + d_i][j + d_j] != WALL:
			dfs(i + d_i, j + d_j)
t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	a = [[WALL] * (m + 2)] + [list(WALL + input() + WALL) for i in range(n)] + [[WALL] * (m + 2)]
	(been, isValid) = ([[0] * (m + 2) for i in range(n + 2)], True)
	for j in range(1, n + 1):
		for k in range(1, m + 1):
			if a[j][k] == BAD_PERSON:
				for (d_i, d_j) in DIR:
					if a[j + d_i][k + d_j] == GOOD_PERSON:
						isValid = False
					elif a[j + d_i][k + d_j] != BAD_PERSON:
						a[j + d_i][k + d_j] = WALL
	if a[n][m] != WALL:
		dfs(n, m)
	for j in range(1, n + 1):
		for k in range(1, m + 1):
			if a[j][k] == GOOD_PERSON and (not been[j][k]):
				isValid = False
	print('Yes' if isValid else 'No')


import os
import sys
from io import BytesIO, IOBase
profile = 0
pypy = 1

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))

class Disjoint_set:

	class node:

		def __init__(self, a):
			self.value = a
			self.p = self
			self.rank = 0

	def __init__(self, a):
		self.data = {i: self.make_set(i) for i in a}

	def make_set(self, val):
		return self.node(val)

	def union(self, x, y):
		self.link(self.find_set(self.data[x]), self.find_set(self.data[y]))

	def link(self, val1, val2):
		if val1.rank > val2.rank:
			val2.p = val1
			val1.rank += 1
		else:
			val1.p = val2
			val2.rank += 1

	def find_set(self, val):
		if val.p.value != val.value:
			val.p = self.find_set(val.p)
		return val.p

	def find_parent(self, val):
		return self.find_set(self.data[val]).value

def main():
	T = iin()
	dc = {'.': 0, '#': 1, 'G': 2, 'B': 3}
	while T:
		T -= 1
		(n, m) = lin()
		a = [[dc[j] for j in input()] for i in range(n)]
		for i in range(n):
			for j in range(m):
				if a[i][j] == 3:
					if i > 0 and a[i - 1][j] == 0:
						a[i - 1][j] = 1
					if j > 0 and a[i][j - 1] == 0:
						a[i][j - 1] = 1
					if i < n - 1 and a[i + 1][j] == 0:
						a[i + 1][j] = 1
					if j < m - 1 and a[i][j + 1] == 0:
						a[i][j + 1] = 1
		arr = []
		for i in range(n):
			for j in range(m):
				arr.append((i, j))
		ds = Disjoint_set(arr)
		for i in range(n):
			for j in range(m):
				if a[i][j] == 1:
					continue
				if i > 0 and a[i - 1][j] != 1:
					ds.union((i, j), (i - 1, j))
				if j > 0 and a[i][j - 1] != 1:
					ds.union((i, j), (i, j - 1))
				if i < n - 1 and a[i + 1][j] != 1:
					ds.union((i, j), (i + 1, j))
				if j < m - 1 and a[i][j + 1] != 1:
					ds.union((i, j), (i, j + 1))
		parent = ds.find_parent((n - 1, m - 1))
		ans = True
		for i in range(n):
			for j in range(m):
				if a[i][j] == 2:
					if ds.find_parent((i, j)) != parent:
						ans = False
				elif a[i][j] == 3:
					if ds.find_parent((i, j)) == parent:
						ans = False
		print('Yes' if ans else 'No')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
if pypy:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
	input = lambda : sys.stdin.readline().rstrip('\r\n')
if profile:
	import cProfile
	cProfile.run('main()')
else:
	main()


from collections import Counter
from collections import defaultdict
from collections import deque
import math
import heapq
import sys
import io, os
input = sys.stdin.readline
from bisect import *
rs = lambda : input().strip()
ri = lambda : int(input())
rl = lambda : list(map(int, input().split()))
rls = lambda : list(map(str, input().split()))

def check(i, j):
	if i >= 0 and i < r and (j >= 0) and (j < c):
		return 1
	return 0
x = [1, 0, -1, 0]
y = [0, 1, 0, -1]

def dfs(i, j):
	if check(i, j) == 0 or a[i][j] == '#':
		return -1
	if i == n - 1 and j == m - 1:
		return 1
	for p in range(0, 4):
		x1 = i + x[p]
		y1 = j + y[p]
		print('scene', x1, y1)
		mx = -1
		if check(x1, y1) and vis[x1][y1] == 0:
			vis[x1][y1] = 1
			ans = dfs(x1, y1)
			print(x1, y1, ans)
			if ans == 1:
				if a[i][j] == 'B':
					if a[x1][y1] == '.':
						a[x1][y1] = '#'
			else:
				vis[x1][y1] = 0
			mx = max(mx, ans)
	return mx
t = int(input())
for _ in range(0, t):
	(r, c) = rl()
	n = r
	m = c
	a = []
	store = []
	vis = []
	for k in range(0, r):
		vis.append([0] * c)
	for i in range(0, r):
		a.append(list(input().strip()))
	c1 = 0
	for i in range(0, r):
		for j in range(0, c):
			if a[i][j] == 'B':
				for p in range(0, 4):
					x1 = i + x[p]
					y1 = j + y[p]
					if check(x1, y1) == 1 and a[x1][y1] == '.':
						a[x1][y1] = '#'
			if a[i][j] == 'G':
				c1 = c1 + 1
	if a[n - 1][m - 1] == '#':
		if c1 == 0:
			print('Yes')
		else:
			print('No')
	else:
		l = []
		q = deque(l)
		g = 0
		q.append([n - 1, m - 1, '.'])
		vis[n - 1][m - 1] = 1
		f1 = 1
		while len(q) != 0:
			(i, j, ele) = q.popleft()
			if ele == 'G':
				g = g + 1
			if ele == 'B':
				f1 = 0
				break
			for p in range(0, 4):
				x1 = i + x[p]
				y1 = j + y[p]
				if check(x1, y1) == 1 and a[x1][y1] != '#' and (vis[x1][y1] == 0):
					vis[x1][y1] = 1
					q.append([x1, y1, a[x1][y1]])
		if g == c1 and f1 == 1:
			print('Yes')
		else:
			print('No')


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')


import math
import sys
sys.setrecursionlimit(10 ** 4)

def Divisors(n):
	l = []
	i = 1
	while i <= math.sqrt(n):
		if n % i == 0:
			if n // i == i:
				l.append(i)
			else:
				l.append(i)
				l.append(n // i)
		i = i + 1
	return l

def SieveOfEratosthenes(n):
	l = []
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	for p in range(2, n + 1):
		if prime[p]:
			l.append(p)
	return l

def primeFactors(n):
	l = []
	while n % 2 == 0:
		l.append(2)
		n = n / 2
	for i in range(3, int(math.sqrt(n)) + 1, 2):
		while n % i == 0:
			l.append(i)
			n = n / i
	if n > 2:
		l.append(n)
	return l

def Factors(n):
	result = []
	for i in range(2, int(math.sqrt(n)) + 1):
		if n % i == 0:
			if i == n / i:
				result.append(i)
			else:
				result.append(i)
				result.append(n // i)
	result.append(1)
	result.append(n)
	return result

def maxSubArraySum(a):
	max_so_far = 0
	max_ending_here = 0
	size = len(a)
	for i in range(0, size):
		max_ending_here = max_ending_here + a[i]
		if max_so_far < max_ending_here:
			max_so_far = max_ending_here
		if max_ending_here < 0:
			max_ending_here = 0
	return max_so_far

def dfs(l, x, y, n, m, s):
	if x < 0 or y < 0 or x >= n or (y >= m):
		return
	if l[x][y] != '#' and s[x][y] != 1:
		s[x][y] = 1
		dfs(l, x - 1, y, n, m, s)
		dfs(l, x, y - 1, n, m, s)
		dfs(l, x, y + 1, n, m, s)
		dfs(l, x + 1, y, n, m, s)
	elif l[x][y] == '#':
		return

def main():
	(n, m) = list(map(int, input().split()))
	l = []
	s = []
	for j in range(0, n):
		l.append(list(input()))
	for j in range(0, n):
		l1 = []
		for k in range(0, m):
			l1.append(-1)
		s.append(l1)
	c = 0
	for j in range(n - 1, -1, -1):
		f = 0
		for k in range(m - 1, -1, -1):
			if l[j][k] == 'B':
				if k - 1 >= 0:
					if l[j][k - 1] == '.':
						l[j][k - 1] = '#'
				if j - 1 >= 0:
					if l[j - 1][k] == '.':
						l[j - 1][k] = '#'
				if k + 1 < m:
					if l[j][k + 1] == '.':
						l[j][k + 1] = '#'
				if j + 1 < n:
					if l[j + 1][k] == '.':
						l[j + 1][k] = '#'
			elif l[j][k] == 'G':
				c += 1
	if l[n - 1][m - 1] == '#' and c > 0:
		print('No')
	else:
		f = 0
		r = dfs(l, n - 1, m - 1, n, m, s)
		for j in range(0, n):
			for k in range(0, m):
				if l[j][k] == 'G' and s[j][k] == -1:
					f = 1
					break
				elif l[j][k] == 'B' and s[j][k] == 1:
					f = 1
					break
			if f == 1:
				break
		if f == 1:
			print('No')
		else:
			print('Yes')
t = int(input())
for i in range(0, t):
	main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [list(input()) for _ in range(n)]
	c = 0
	cg = 0
	b = 0
	for i in range(n):
		for j in range(m):
			if a[i][j] == 'B':
				b += 1
				if i > 0:
					if a[i - 1][j] == 'G':
						c = 1
						break
					if a[i - 1][j] != 'B':
						a[i - 1][j] = '#'
				if j > 0:
					if a[i][j - 1] == 'G':
						c = 1
						break
					if a[i][j - 1] != 'B':
						a[i][j - 1] = '#'
				if i < n - 1:
					if a[i + 1][j] == 'G':
						c = 1
						break
					if a[i + 1][j] != 'B':
						a[i + 1][j] = '#'
				if j < m - 1:
					if a[i][j + 1] == 'G':
						c = 1
						break
					if a[i][j + 1] != 'B':
						a[i][j + 1] = '#'
			elif a[i][j] == 'G':
				cg += 1
		if c == 1:
			break
	if c == 1:
		print('No')
	elif cg == 0:
		print('Yes')
	elif a[n - 1][m - 1] == '#':
		print('No')
	else:
		cgg = 0
		used = set()
		used.add((n - 1, m - 1))
		cur = [[n - 1, m - 1]]
		while cur != []:
			(i, j) = cur.pop(0)
			if a[i][j] == 'G':
				cgg += 1
			if a[i][j] == '#':
				continue
			if i > 0 and (i - 1, j) not in used:
				cur.append([i - 1, j])
				used.add((i - 1, j))
			if j > 0 and (i, j - 1) not in used:
				cur.append([i, j - 1])
				used.add((i, j - 1))
			if i < n - 1 and (i + 1, j) not in used:
				cur.append([i + 1, j])
				used.add((i + 1, j))
			if j < m - 1 and (i, j + 1) not in used:
				cur.append([i, j + 1])
				used.add((i, j + 1))
		if cgg == cg:
			print('Yes')
		else:
			print('No')


import sys
from itertools import product
t = int(sys.stdin.readline())

def adj(i, j, n, m):
	if i - 1 != -1:
		yield (i - 1, j)
	if i + 1 != n:
		yield (i + 1, j)
	if j - 1 != -1:
		yield (i, j - 1)
	if j + 1 != m:
		yield (i, j + 1)

def floodfill(maze, x0, y0, n, m):
	if maze[x0][y0] == '#':
		return
	maze[x0][y0] = '#'
	for (i, j) in adj(x0, y0, n, m):
		floodfill(maze, i, j, n, m)
for _ in range(t):
	(n, m) = [int(i) for i in sys.stdin.readline().split()]
	maze = []
	for _ in range(n):
		maze = maze + [[c for c in sys.stdin.readline().rstrip()]]
	pos = True
	for (x, y) in product(range(n), range(m)):
		if maze[x][y] == 'B':
			maze[x][y] = '#'
			for (i, j) in adj(x, y, n, m):
				if maze[i][j] == 'G':
					pos = False
				if maze[i][j] != 'B':
					maze[i][j] = '#'
	if not pos:
		print('No')
		continue
	floodfill(maze, n - 1, m - 1, n, m)
	pos = True
	for row in maze:
		for cell in row:
			if cell == 'G':
				pos = False
	if pos:
		print('Yes')
	else:
		print('No')


dx = [1, 0, -1, 0]
dy = [0, 1, 0, -1]

def bfs(l, gc):
	v = set()
	v.add((len(l) - 1, len(l[0]) - 1))
	q = [(len(l) - 1, len(l[0]) - 1)]
	gset = set()
	while q:
		(c, b) = q.pop(0)
		if l[c][b] == 'G':
			gset.add((c, b))
		for j in range(4):
			nx = c + dx[j]
			ny = b + dy[j]
			if nx >= 0 and nx < len(l) and (ny >= 0) and (ny < len(l[0])) and (l[nx][ny] in ['.', 'G']):
				if (nx, ny) not in v:
					v.add((nx, ny))
					q.append((nx, ny))
	return gc - len(gset)
import copy
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(list(input()))
	f = 0
	gc = 0
	for i in range(n):
		for j in range(m):
			if l[i][j] == 'G':
				gc += 1
	for i in range(n):
		for j in range(m):
			if l[i][j] == 'G':
				continue
			if l[i][j] == 'B':
				for k in range(4):
					nx = i + dx[k]
					ny = j + dy[k]
					if nx >= 0 and nx < len(l) and (ny >= 0) and (ny < len(l[0])):
						if l[nx][ny] == 'G':
							f = 1
							break
						elif l[nx][ny] == '.':
							l[nx][ny] = '#'
		if f:
			break
	if gc == 0:
		print('Yes')
		continue
	if f or l[-1][-1] == '#':
		print('No')
		continue
	if bfs(l, gc) == 0:
		print('Yes')
	else:
		print('No')


for t in range(int(input())):
	(n, m) = [int(j) for j in input().split()]
	l = []
	for i in range(n):
		l.append(['#'] + list(input()) + ['#'])
	l = [['#' for i in range(m + 2)]] + l + [['#' for i in range(m + 2)]]
	flag = True
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if l[i][j] == 'B':
				for k in range(0, 2):
					if l[i + k][j + 1 - k] == 'G' or l[i - k][j - 1 + k] == 'G':
						flag = False
				l[i][j] = '#'
				for k in range(0, 2):
					if l[i + k][j + 1 - k] == '.':
						l[i + k][j + 1 - k] = '#'
					if l[i - k][j - 1 + k] == '.':
						l[i - k][j - 1 + k] = '#'
	visited = dict()
	st = []
	if l[n][m] != '#':
		st.append((n, m))
	while st:
		(i, j) = st.pop(0)
		for k in range(0, 2):
			if l[i + k][j + 1 - k] != '#' and (i + k, j + 1 - k) not in visited:
				visited[i + k, j + 1 - k] = True
				st.append((i + k, j + 1 - k))
			if l[i - k][j - 1 + k] != '#' and (i - k, j - 1 + k) not in visited:
				visited[i - k, j - 1 + k] = True
				st.append((i - k, j - 1 + k))
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if l[i][j] == 'G':
				if (i, j) not in visited:
					flag = False
	if flag:
		print('Yes')
	else:
		print('No')


import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)
for t in range(int(input())):
	(n, m) = list(map(int, input().split()))
	data = [list(input().strip()) for i in range(n)]
	allowed = ['G', 'B', '.']
	directions = [(0, 1), (1, 0), (0, -1), (-1, 0)]

	def valid(i, j):
		return 0 <= i < n and 0 <= j < m and (data[i][j] in allowed)

	def dfs(i, j, mark):
		mark[i][j] = 1
		for (x, y) in directions:
			if valid(x + i, y + j) and (not mark[x + i][y + j]):
				dfs(x + i, y + j, mark)
	for i in range(n):
		for j in range(m):
			if data[i][j] == 'B':
				for (x, y) in directions:
					if valid(i + x, j + y) and data[i + x][j + y] == '.':
						data[i + x][j + y] = '#'
	mark = [[0] * m for i in range(n)]
	if data[n - 1][m - 1] != '#':
		dfs(n - 1, m - 1, mark)
	flag1 = True
	for i in range(n):
		for j in range(m):
			if data[i][j] == 'G' and (not mark[i][j]):
				flag1 = False
	flag2 = True
	for i in range(n):
		for j in range(m):
			if data[i][j] == 'B' and mark[i][j]:
				flag2 = False
	print('Yes' if all((flag1, flag2)) else 'No')


import sys
input = sys.stdin.readline
import heapq
import copy
import math

def inp():
	return int(input())

def inlt():
	return list(map(int, input().split()))

def insr():
	s = input()
	return list(s[:len(s) - 1])

def invr():
	return map(int, input().split())

class Node:

	def _init_(self, val):
		self.data = val
		self.left = None
		self.right = None

def pre_sum(arr):
	p = [0]
	for i in arr:
		p.append(p[-1] + i)
	p.pop(0)
	return p

def pre_back(arr):
	p = [0]
	for i in arr:
		p.append(p[-1] + i)
	p.pop(0)
	return p

def bin_search(arr, l, r, val):
	if arr[r] <= val:
		return r + 1
	if r - l < 2:
		if arr[l] > val:
			return l
		else:
			return r
	mid = int((l + r) / 2)
	if arr[mid] <= val:
		return bin_search(arr, mid, r, val)
	else:
		return bin_search(arr, l, mid, val)

def search_leftmost(arr, val):

	def helper(arr, l, r, val):
		print(l, r)
		if arr[l] == val:
			return l
		if r - l <= 1:
			if arr[r] == val:
				return r
			else:
				print('not found')
				return
		mid = int((r + l) / 2)
		if arr[mid] >= val:
			return helper(arr, l, mid, val)
		else:
			return helper(arr, mid, r, val)
	return helper(arr, 0, len(arr) - 1, val)

def search_rightmost(arr, val):

	def helper(arr, l, r, val):
		print(l, r)
		if arr[r] == val:
			return r
		if r - l <= 1:
			if arr[l] == val:
				return r
			else:
				print('not found')
				return
		mid = int((r + l) / 2)
		if arr[mid] > val:
			return helper(arr, l, mid, val)
		else:
			return helper(arr, mid, r, val)
	return helper(arr, 0, len(arr) - 1, val)

def pr_list(a):
	print(*a, sep=' ')

def main():
	tests = inp()
	mod = 1000000007
	limit = 10 ** 18
	for test in range(tests):
		[n, m] = inlt()
		maze = []
		for i in range(n):
			maze.append(insr())
		good = {}
		flag = 0
		for i in range(n):
			for j in range(m):
				if maze[i][j] == 'G':
					good[i, j] = 1
				elif maze[i][j] == 'B':
					if i + 1 < n:
						if maze[i + 1][j] == 'G':
							flag = 1
						elif maze[i + 1][j] != 'B':
							maze[i + 1][j] = '#'
					if j + 1 < m:
						if maze[i][j + 1] == 'G':
							flag = 1
						elif maze[i][j + 1] != 'B':
							maze[i][j + 1] = '#'
					if i - 1 >= 0:
						if maze[i - 1][j] == 'G':
							flag = 1
						elif maze[i - 1][j] != 'B':
							maze[i - 1][j] = '#'
					if j - 1 >= 0:
						if maze[i][j - 1] == 'G':
							flag = 1
						elif maze[i][j - 1] != 'B':
							maze[i][j - 1] = '#'
		if good == {}:
			print('Yes')
			continue
		if flag == 1 or maze[n - 1][m - 1] == '#' or maze[n - 1][m - 1] == 'B':
			print('No')
			continue
		flag = 0
		queue = [(n - 1, m - 1)]
		done = [[0 for i in range(m)] for j in range(n)]
		done[-1][-1] = 1
		if (n - 1, m - 1) in good:
			del good[n - 1, m - 1]
		while queue != []:
			curr = queue.pop(0)
			i = curr[0]
			j = curr[1]
			if (i, j) in good:
				del good[i, j]
			if i - 1 >= 0 and maze[i - 1][j] != '#' and (done[i - 1][j] == 0):
				queue.append((i - 1, j))
				done[i - 1][j] = 1
			if j - 1 >= 0 and maze[i][j - 1] != '#' and (done[i][j - 1] == 0):
				queue.append((i, j - 1))
				done[i][j - 1] = 1
			if i + 1 < n and maze[i + 1][j] != '#' and (done[i + 1][j] == 0):
				queue.append((i + 1, j))
				done[i + 1][j] = 1
			if j + 1 < m and maze[i][j + 1] != '#' and (done[i][j + 1] == 0):
				queue.append((i, j + 1))
				done[i][j + 1] = 1
		if good != {}:
			print('No')
		else:
			print('Yes')
main()


from collections import deque
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	L = [list(input()) for _ in range(n)]
	for i in range(n):
		L[i] = ['#'] + L[i] + ['#']
	L.insert(0, ['#'] * (m + 2))
	L.append(['#'] * (m + 2))
	ans = 'Yes'
	G = []
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if L[i][j] == 'G':
				G.append((i, j))
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if L[i][j] == 'B':
				L[i - 1][j] = '#'
				if L[i + 1][j] != 'B':
					L[i + 1][j] = '#'
				L[i][j - 1] = '#'
				if L[i][j + 1] != 'B':
					L[i][j + 1] = '#'
	q = deque()
	q.append((n, m))
	used = [[0] * (m + 2) for _ in range(n + 2)]
	used[n][m] = 1
	while L[n][m] != '#' and q:
		temp = q.pop()
		i = temp[0]
		j = temp[1]
		if L[i - 1][j] != '#' and used[i - 1][j] == 0:
			used[i - 1][j] = 1
			q.append((i - 1, j))
		if L[i + 1][j] != '#' and used[i + 1][j] == 0:
			used[i + 1][j] = 1
			q.append((i + 1, j))
		if L[i][j - 1] != '#' and used[i][j - 1] == 0:
			used[i][j - 1] = 1
			q.append((i, j - 1))
		if L[i][j + 1] != '#' and used[i][j + 1] == 0:
			used[i][j + 1] = 1
			q.append((i, j + 1))
	for g in G:
		if used[g[0]][g[1]] == 0:
			ans = 'No'
			break
	print(ans)


from collections import deque
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	g = [['#'] * (m + 2)]
	for i in range(n):
		g.append(['#'] + list(input()) + ['#'])
	g.append(['#'] * (m + 2))
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if g[i][j] == 'B':
				if g[i + 1][j] == '.':
					g[i + 1][j] = '#'
				if g[i - 1][j] == '.':
					g[i - 1][j] = '#'
				if g[i][j + 1] == '.':
					g[i][j + 1] = '#'
				if g[i][j - 1] == '.':
					g[i][j - 1] = '#'
	visit = [[False] * (m + 2) for i in range(n + 2)]
	visit[n][m] = True
	ans = 'Yes'
	q = deque([(n, m)])
	while q:
		(x, y) = q.popleft()
		for (dx, dy) in [(1, 0), (-1, 0), (0, -1), (0, 1)]:
			if g[x + dx][y + dy] != '#':
				if not visit[x + dx][y + dy]:
					q.append((x + dx, y + dy))
					visit[x + dx][y + dy] = True
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if g[i][j] == 'G':
				if not visit[i][j]:
					ans = 'No'
			if g[i][j] == 'B':
				if visit[i][j]:
					ans = 'No'
	f = 0
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if g[i][j] == 'G':
				f = 1
	if f == 1:
		if g[n][m] == '#':
			ans = 'No'
	else:
		ans = 'Yes'
	print(ans)


from sys import stdin
input = stdin.readline
g = []
vis = []
dx = [0, 0, 1, -1]
dy = [1, -1, 0, 0]

def dfs(s):
	q = [s]
	vis[s[0]][s[1]] = 1
	while q:
		(x, y) = q.pop()
		for i in range(4):
			if 0 <= x + dx[i] < n and 0 <= y + dy[i] < m:
				if not vis[x + dx[i]][y + dy[i]] and g[x + dx[i]][y + dy[i]] != '#':
					vis[x + dx[i]][y + dy[i]] = (1, q.append((x + dx[i], y + dy[i])))
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	gg = [list(input()[:-1]) for i in range(n)]
	g = [[gg[i][j] for j in range(m)] for i in range(n)]
	cnt = 0
	for i in g:
		cnt += i.count('G')
	if not cnt:
		print('Yes')
		continue
	for x in range(n):
		for y in range(m):
			if gg[x][y] == 'B':
				for i in range(4):
					if 0 <= x + dx[i] < n and 0 <= y + dy[i] < m:
						if g[x + dx[i]][y + dy[i]] == '.':
							g[x + dx[i]][y + dy[i]] = '#'
	if g[n - 1][m - 1] == 'B':
		print('No')
		continue
	vis = [[0 for j in range(m)] for i in range(n)]
	if g[n - 1][m - 1] != '#':
		dfs((n - 1, m - 1))
	flag = 1
	for x in range(n):
		for y in range(m):
			if g[x][y] == 'G' and (not vis[x][y]):
				flag = 0
				break
			if g[x][y] == 'B' and vis[x][y]:
				flag = 0
				break
		if not flag:
			break
	if flag:
		print('Yes')
	else:
		print('No')


import sys
sys.setrecursionlimit(10000)

def yn(arr, n, m):
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 'B':
				if j - 1 >= 0 and arr[i][j - 1] != 'G' and (arr[i][j - 1] != 'B'):
					arr[i][j - 1] = '#'
				if j + 1 < m and arr[i][j + 1] != 'G' and (arr[i][j + 1] != 'B'):
					arr[i][j + 1] = '#'
				if i - 1 >= 0 and arr[i - 1][j] != 'G' and (arr[i - 1][j] != 'B'):
					arr[i - 1][j] = '#'
				if i + 1 < n and arr[i + 1][j] != 'G' and (arr[i + 1][j] != 'B'):
					arr[i + 1][j] = '#'
				if j - 1 >= 0 and arr[i][j - 1] == 'G':
					return 1
				if j + 1 < m and arr[i][j + 1] == 'G':
					return 1
				if i - 1 >= 0 and arr[i - 1][j] == 'G':
					return 1
				if i + 1 < n and arr[i + 1][j] == 'G':
					return 1
	return 0

def solve(arr, i, j, n, m):
	if i < 0 or i >= n or j >= m or (j < 0) or (arr[i][j] == '#') or (vis[i][j] == 1) or (arr[i][j] == 'B'):
		return
	vis[i][j] = 1
	if i > 0:
		solve(arr, i - 1, j, n, m)
	if j > 0:
		solve(arr, i, j - 1, n, m)
	if i < n - 1:
		solve(arr, i + 1, j, n, m)
	if j < m - 1:
		solve(arr, i, j + 1, n, m)
for _ in range(int(input())):
	vis = [[0] * 62 for i in range(62)]
	(n, m) = map(int, input().split())
	arr = []
	ng = 0
	gc = 0
	for i in range(n):
		arr.append(list(input()))
		ng += arr[-1].count('G')
	if yn(arr, n, m):
		print('No')
	else:
		solve(arr, n - 1, m - 1, n, m)
		for i in range(n):
			for j in range(m):
				if vis[i][j] == 1 and arr[i][j] == 'G':
					gc += 1
		if ng == gc:
			print('Yes')
		else:
			print('No')


for i in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(list(input()))
	f = 0
	c1 = 0
	for i in range(n):
		for j in range(m):
			if l[i][j] == 'B':
				if i - 1 >= 0:
					if l[i - 1][j] == 'G':
						f = 1
						break
					elif l[i - 1][j] == '.':
						l[i - 1][j] = '#'
				if i + 1 < n:
					if l[i + 1][j] == 'G':
						f = 1
						break
					elif l[i + 1][j] == '.':
						l[i + 1][j] = '#'
				if j + 1 < m:
					if l[i][j + 1] == 'G':
						f = 1
						break
					elif l[i][j + 1] == '.':
						l[i][j + 1] = '#'
				if j - 1 >= 0:
					if l[i][j - 1] == 'G':
						f = 1
						break
					elif l[i][j - 1] == '.':
						l[i][j - 1] = '#'
			elif l[i][j] == 'G':
				c1 += 1
		if f == 1:
			print('No')
			break
	if f == 0:
		c = 0
		f = 0
		s = set()
		q = [(n - 1, m - 1)]
		s.add((n - 1, m - 1))
		for cell in q:
			(a, b) = cell
			if l[a][b] == '#':
				continue
			elif l[a][b] == 'G':
				c += 1
			elif l[a][b] == 'B':
				f = 1
			if a - 1 >= 0:
				if (a - 1, b) not in s:
					s.add((a - 1, b))
					q.append((a - 1, b))
			if a + 1 < n:
				if (a + 1, b) not in s:
					s.add((a + 1, b))
					q.append((a + 1, b))
			if b + 1 < m:
				if (a, b + 1) not in s:
					s.add((a, b + 1))
					q.append((a, b + 1))
			if b - 1 >= 0:
				if (a, b - 1) not in s:
					s.add((a, b - 1))
					q.append((a, b - 1))
		if f == 1 or c != c1:
			print('No')
		else:
			print('Yes')


def solve(grid, n, m, ans):
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 'B':
				if i + 1 < n:
					if grid[i + 1][j] == '.':
						grid[i + 1][j] = '#'
				if j + 1 < m:
					if grid[i][j + 1] == '.':
						grid[i][j + 1] = '#'
				if i - 1 >= 0:
					if grid[i - 1][j] == '.':
						grid[i - 1][j] = '#'
				if j - 1 >= 0:
					if grid[i][j - 1] == '.':
						grid[i][j - 1] = '#'
	if grid[n - 1][m - 1] == '.':
		stack = [(n - 1, m - 1)]
	else:
		stack = []
	visited = set()
	while stack:
		(x, y) = stack.pop()
		if (x, y) not in visited:
			visited.add((x, y))
			if x + 1 < n and grid[x + 1][y] != '#':
				stack.append((x + 1, y))
			if y + 1 < m and grid[x][y + 1] != '#':
				stack.append((x, y + 1))
			if x - 1 >= 0 and grid[x - 1][y] != '#':
				stack.append((x - 1, y))
			if y - 1 >= 0 and grid[x][y - 1] != '#':
				stack.append((x, y - 1))
	for i in range(n):
		for j in range(m):
			if grid[i][j] == 'G' and (i, j) not in visited:
				ans.append('No')
				return
			if grid[i][j] == 'B' and (i, j) in visited:
				ans.append('No')
				return
	ans.append('Yes')

def main():
	t = int(input())
	ans = []
	for i in range(t):
		(n, m) = map(int, input().split())
		grid = []
		for j in range(n):
			grid.append(list(input()))
		solve(grid, n, m, ans)
	for i in ans:
		print(i)
main()


from __future__ import division, print_function
import os
import sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def solve(t):
	(n, m) = map(int, input().strip().split())
	data = []
	for i in range(n):
		data.append(list(input()))
	no_of_goods = 0
	for i in range(n):
		for j in range(m):
			if data[i][j] == 'B':
				nxts = [(1, 0), (-1, 0), (0, 1), (0, -1)]
				for (x, y) in nxts:
					if i + x >= 0 and j + y >= 0 and (i + x < n) and (j + y < m):
						if data[i + x][j + y] == 'G':
							return 'No'
						if data[i + x][j + y] == '.':
							data[i + x][j + y] = '#'
			if data[i][j] == 'G':
				no_of_goods += 1
	if data[n - 1][m - 1] == '#':
		return 'No' if no_of_goods > 0 else 'Yes'
	reachable = [[False for i in range(m)] for j in range(n)]
	from collections import deque
	qq = deque()
	qq.append((n - 1, m - 1))
	nxts = [(1, 0), (-1, 0), (0, 1), (0, -1)]
	while qq:
		(x, y) = qq.popleft()
		if reachable[x][y]:
			continue
		if data[x][y] == '#':
			continue
		if data[x][y] == 'B':
			return 'No'
		reachable[x][y] = True
		for (i, j) in nxts:
			if x + i < 0 or y + j < 0 or x + i >= n or (y + j >= m):
				continue
			qq.append((x + i, y + j))
	for i in range(n):
		for j in range(m):
			if data[i][j] == 'G' and reachable[i][j] == False:
				return 'No'
	return 'Yes'

def main():
	tc = int(input().strip())
	for t in range(1, tc + 1):
		print(solve(t))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()