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