for _ in range(int(input())):
    n, m = map(int, input().split())
    layout = tuple((list(input().lower()) for _ in range(n)))
    trapped_greens = ''.join(map(''.join, layout)).count('g')
    all_blues = tuple(((i, j) for i in range(n) for j in range(m) if layout[i][j] == 'b'))
    for i, j in all_blues:
        if i:
            layout[i - 1][j] = '#'
        if j:
            layout[i][j - 1] = '#'
        if i + 1 < n:
            layout[i + 1][j] = '#'
        if j + 1 < m:
            layout[i][j + 1] = '#'
    stack = [(n - 1, m - 1)]
    while stack:
        i, j = stack.pop()
        if layout[i][j] != '#':
            if layout[i][j] == 'g':
                trapped_greens -= 1
            layout[i][j] = '#'
            if i:
                stack.append((i - 1, j))
            if j:
                stack.append((i, j - 1))
            if i + 1 < n:
                stack.append((i + 1, j))
            if j + 1 < m:
                stack.append((i, j + 1))
    if trapped_greens:
        print("No")
    else:
        print("Yes")
