# -*- coding: utf-8 -*-
from collections import defaultdict
import sys
# sys.setrecursionlimit(10**6)
# buff_readline = sys.stdin.buffer.readline
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



# @mt
def slv(N, M, G):
    G = [[ c for c in r] for r in G]
    # print(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'
    # print(G)



    # for i in range(1, N):

    # k = [[], []]
    # for a, b in zip(A, B):
    #     k[b].append(a)
    # if tuple(k[0]) == tuple(sorted(k[0])) and tuple(k[1]) == tuple(sorted(k[1])):
    #     return 'Yes'
    # return 'No'


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


if __name__ == '__main__':
    main()
