def bfs(a, b, l, n, m):
    queue = [(a, b)]
    vis = [(a, b)]
    while queue:
        for i in queue:
            next = []
            if i[1] != m - 1 and l[i[0]][i[1] + 1] in ['.', 'G'] and (i[0], i[1] + 1) not in vis:
                next.append((i[0], i[1] + 1))
            if i[1] != 0 and l[i[0]][i[1] - 1] in ['.', 'G'] and (i[0], i[1] - 1) not in vis:
                next.append((i[0], i[1] - 1))
            if i[0] != n - 1 and l[i[0] + 1][i[1]] in ['.', 'G'] and (i[0] + 1, i[1]) not in vis:
                next.append((i[0] + 1, i[1]))
            if i[0] != 0 and l[i[0] - 1][i[1]] in ['.', 'G'] and (i[0] - 1, i[1]) not in vis:
                next.append((i[0] - 1, i[1]))
        queue = next
        vis += next
    return (n - 1, m - 1) in vis

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