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]
        #print(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
        #print(visit)
        if flag:
            print('Yes')
        else:
            print('No')

if __name__ == '__main__':
    main()
