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