def checkPath(maze, i, j, n, m, check):
    if i<0 or i==n or j<0 or j==m or check[i][j] == 1 or maze[i][j] == 'B' or maze[i][j] == '#':
        return False
    elif i == n-1 and j == m-1:
        return True
    else:
        check[i][j] = 1
        if(checkPath(maze,i-1, j, n, m, check) or checkPath(maze, i, j-1, n, m, check)
          or checkPath(maze, i+1, j, n, m, check) or checkPath(maze, i, j+1, n, m, check)):
            return True
        return False
def checkN(maze, i, j, n, m):
    if(checkNeighbor(maze,i-1, j, n, m) == True or checkNeighbor(maze, i, j-1, n, m) == True
          or checkNeighbor(maze, i+1, j, n, m) == True or checkNeighbor(maze, i, j+1, n, m) == True):
        return True
    return False
def checkNeighbor(maze, i, j, n, m):
    if i<0 or i==n or j<0 or j==m:
        return False
    else:
        if maze[i][j] == 'B':
            return True
        else:
            return False
t = int(input())
while t>0:
    n, m = [int(ele) for ele in input().split()]
    maze = []
    check = []
    for i in range(n):
        lst = list(input())
        maze.append(lst)
    
    count_G = 0
    count_B = 0
    
    for row in maze:
        for ele in row:
            if ele == 'B':
                count_B += 1
            elif ele == 'G':
                count_G += 1
    
    if(maze[n-1][m-2] == 'B' or maze[n-2][m-1] == 'B') and count_G != 0:
        print('NO')
    else:
        if count_G == 0 and count_B == 0:
            print('YES')
        elif count_G == 0:
            print('YES')
        elif count_B == 0:
            flag = 0
            for i in range(n):
                for j in range(m):
                    if (maze[i][j] == 'G'):
                        check = []
                        for u in range(n):
                            check.append([0 for _ in range(m)])
                        if(checkPath(maze, i, j, n, m, check) == False):
                            flag = 1
                            break

                if(flag == 1):
                    break
            if(flag == 1):
                print('NO')
            else:
                print('YES')
        else:
            flag = 0
            for i in range(n):
                for j in range(m):
                    if (maze[i][j] == 'G'):
                        if checkN(maze, i, j, n, m) == True:
                            flag = 1
                            break 
                if(flag == 1):
                    break
            if(flag == 1):
                print('NO')
            else:
                flag = 0
                for i in range(n):
                    for j in range(m):
                        if (maze[i][j] == 'G'):
                            check = []
                            for u in range(n):
                                check.append([0 for _ in range(m)])
                            if(checkPath(maze, i, j, n, m, check) == False):
                                flag = 1
                                break

                    if(flag == 1):
                        break
                if(flag == 1):
                    print('NO')
                else:
                    print('YES')
    t -= 1

