from sys import stdin, stdout

def main():
    t = int(stdin.readline())
    for _ in range (t):
        n,m = list(map(int, stdin.readline().split()))
        mp = []
        for _ in range(n):
            tmp = stdin.readline().strip()
            newer = []
            for x in tmp:
                newer.append(x)
            mp.append(newer)
        cnt = 0
        wrong = False
        for i in range(n):
            for j in range(m):
                if mp[i][j] == "G":
                    cnt += 1
                if mp[i][j] == "B":
                    if i > 0 and mp[i-1][j] == ".":
                        mp[i-1][j] = "#"
                    if j > 0 and mp[i][j-1] == ".":
                        mp[i][j-1] = "#"
                    if i + 1 < n and mp[i+1][j] == ".":
                        mp[i+1][j] = "#"
                    if j + 1 < m and mp[i][j+1] == ".":
                        mp[i][j+1] = "#"
        stack = []
        stack.append((n-1,m-1))
        res = 0
        visited = [[False for _ in range(m)] for _ in range(n)]
        visited[n-1][m-1] = True
        if mp[n-1][m-1] == "#":
            pass
        else:
            while stack:
                new_stack = set()
                for x,y in stack:
                    if x > 0 and not visited[x-1][y] and mp[x-1][y] != "#":
                        new_stack.add((x-1,y))
                        visited[x-1][y] = True
                        if mp[x-1][y] == "G":
                            res += 1
                        if mp[x-1][y] == "B":
                            wrong = True
                            break
                    if y> 0 and not visited[x][y-1] and mp[x][y-1] != "#":
                        new_stack.add((x,y-1))
                        visited[x][y-1] = True
                        if mp[x][y-1] == "G":
                            res += 1
                        if mp[x][y-1] == "B":
                            wrong = True
                            break
                    if x +1 < n and not visited[x+1][y] and mp[x+1][y] != "#":
                        new_stack.add((x+1,y))
                        visited[x+1][y] = True
                        if mp[x+1][y] == "G":
                            res += 1
                        if mp[x+1][y] == "B":
                            wrong = True
                            break
                    if y + 1 < m and not visited[x][y+1] and mp[x][y+1] != "#":
                        new_stack.add((x,y+1))
                        visited[x][y+1] = True
                        if mp[x][y+1] == "G":
                            res += 1
                        if mp[x][y+1] == "B":
                            wrong = True
                            break
                stack = list(new_stack)
                if wrong:
                    break
        if wrong or res != cnt:
            stdout.write("NO\n")
            continue
        stdout.write("YES\n")

main()