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