import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

"""def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)"""

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""

def dfs(u, visited, good, d, n, m):
    visited[u] = True
    c = [0, False]
    if (u == n * m):
        c[1] = True

    if (good[u] == 'G'):
        c[0] += 1
    for i in d[u]:
        if (visited[i] == False):
            dr = dfs(i, visited, good, d, n, m)
            c[0] += dr[0]
            c[1] ^= dr[1]
    return c

def inar():
    return [int(k) for k in input().split()]

def main():
    for _ in range(int(input())):
        n, m = map(int, input().split())
        good = [0] * (n * m + 1)
        ar = []
        count = 0
        for i in range(n):
            ar.append(list(input()))
        bl = True
        for i in range(n):
            for j in range(m):
                if (ar[i][j] == 'G'):
                    if (j + 1 < m and ar[i][j + 1] == 'B'):
                        bl = False
                    if (j - 1 >= 0 and ar[i][j - 1] == 'B'):
                        bl = False
                    if (i - 1 >= 0 and ar[i - 1][j] == 'B'):
                        bl = False
                    if (i + 1 < n and ar[i + 1][j] == 'B'):
                        bl = False
                    if (bl == False):
                        break
            if (bl == False):
                break
        if (bl == False):
            print('No')
            continue
        for i in range(n):
            for j in range(m):
                if (ar[i][j] == 'G'):
                    count += 1
                if (ar[i][j] == 'B'):
                    if (j + 1 < m and ar[i][j + 1] == '.'):
                        ar[i][j + 1] = '#'
                    if (j - 1 >= 0 and ar[i][j - 1] == '.'):
                        ar[i][j - 1] = '#'
                    if (i - 1 >= 0 and ar[i - 1][j] == '.'):
                        ar[i - 1][j] = '#'
                    if (i + 1 < n and ar[i + 1][j] == '.'):
                        ar[i + 1][j] = '#'

        if (ar[n - 1][m - 1] == '#'):
            print('No')
            continue
        d = defaultdict(list)
        ct = 0
        for i in range(n):
            for j in range(m):
                ct += 1
                if (ar[i][j] == '.' or ar[i][j] == 'G'):
                    if (j + 1 < m and (ar[i][j + 1] == '.' or ar[i][j + 1] == 'G')):
                        d[ct].append(ct + 1)
                    if (j - 1 >= 0 and (ar[i][j - 1] == '.' or ar[i][j - 1] == 'G')):
                        d[ct].append(ct - 1)
                    if (i - 1 >= 0 and (ar[i - 1][j] == '.' or ar[i - 1][j] == 'G')):
                        d[ct].append(ct - m)
                    if (i + 1 < n and (ar[i + 1][j] == '.' or ar[i + 1][j] == 'G')):
                        d[ct].append(ct + m)

                if (ar[i][j] == 'G'):
                    good[ct] = 'G'

        if (len(d) == 0 and count == 0):
            print('Yes')
            continue
        visited = [False] * (n * m + 1)
        ans = False
        for i in range(1, n * m + 1):
            if (i in d):
                val = dfs(i, visited, good, d, n, m)
                # print(val[0],val[1])
                if (val[0] == count and val[1] == True):
                    ans = True
                    break
        if (ans):
            print('Yes')
        else:
            print('No')

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

"""def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)"""

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""

def inar():
    return [int(k) for k in input().split()]

def main():
    for _ in range(int(input())):
        n, m = map(int, input().split())
        ar = []
        for i in range(n):
            ar.append(list(input()))

        for i in range(n):
            for j in range(m):
                if(ar[i][j]=='B'):
                    if(i-1>=0 and ar[i-1][j]=='.'):
                        ar[i-1][j]='#'
                    if (i + 1 < n and ar[i + 1][j] == '.'):
                        ar[i + 1][j] = '#'
                    if (j - 1 >= 0 and ar[i][j-1] == '.'):
                        ar[i][j-1] = '#'
                    if (j + 1 <m and ar[i][j+1] == '.'):
                        ar[i][j+1] = '#'
        q=[]
        visited=[]
        for i in range(n):
            visited.append([False]*m)

        if(ar[n-1][m-1]=='.'):
            q.append((n-1,m-1))
            visited[n-1][m-1]=True
        # visited[n-1][m-1]=False
        while(q):
            pos=q.pop()
            i=pos[0]
            j=pos[1]
            if (i - 1 >= 0 and ar[i - 1][j] != '#' and visited[i-1][j]==False):
                q.append((i-1,j))
                visited[i-1][j]=True
            if (i + 1 < n and ar[i + 1][j] != '#' and visited[i+1][j]==False):
                q.append((i+1,j))
                visited[i + 1][j] = True
            if (j - 1 >= 0 and ar[i][j-1] != '#' and visited[i][j-1]==False):
                q.append((i,j-1))
                visited[i][j - 1] = True
            if (j + 1 < m and ar[i][j+1] != '#' and visited[i][j+1]==False):
                q.append((i,j+1))
                visited[i][j+1] = True
        good=True
        for i in range(n):
            for j in range(m):
                if((ar[i][j]=='G' and visited[i][j]==False) or (ar[i][j]=='B' and visited[i][j]==True)):
                    good=False
                    break
        if(good):
            print('Yes')
        else:
            print('No')

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

"""def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)"""

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""

def inar():
    return [int(k) for k in input().split()]

def main():
    for _ in range(int(input())):
        n, m = map(int, input().split())
        good = [0] * (n * m + 1)
        ar = []
        count = 0
        for i in range(n):
            ar.append(list(input()))
        for i in range(n):
            for j in range(m):
                if(ar[i][j]=='B'):
                    if(i-1>=0 and ar[i-1][j]=='.'):
                        ar[i-1][j]='#'
                    if (i + 1 < n and ar[i + 1][j] == '.'):
                        ar[i + 1][j] = '#'
                    if (j - 1 >= 0 and ar[i][j-1] == '.'):
                        ar[i][j-1] = '#'
                    if (j + 1 <m and ar[i][j+1] == '.'):
                        ar[i][j+1] = '#'
        q=[]
        visited=[]
        for i in range(m):
            visited.append([False]*m)

        for i in range(n):
            for j in range(m):
                if(ar[i][j]=='.'):
                    q.append((i,j))
                    visited[i][j]=True
        while(q):
            pos=q.pop(0)
            i=pos[0]
            j=pos[1]
            visited[i][j]=True
            if (i - 1 >= 0 and ar[i - 1][j] != '#' and visited[i-1][j]==False):
                q.append((i-1,j))
            if (i + 1 < n and ar[i + 1][j] != '#' and visited[i+1][j]==False):
                q.append((i+1,j))
            if (j - 1 >= 0 and ar[i][j-1] != '#' and visited[i][j-1]==False):
                q.append((i,j-1))
            if (j + 1 < m and ar[i][j+1] != '#' and visited[i][j+1]==False):
                q.append((i,j+1))

        good=True
        for i in range(n):
            for j in range(m):
                if((ar[i][j]=='G' and visited[i][j]==False) or (ar[i][j]=='B' and visited[i][j]==True)):
                    good=False
                    break
            if(not good):
                break
        if(good):
            print('Yes')
        else:
            print('No')
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

"""def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)"""

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""

def dfs(u,visited,good,d,n,m):
    visited[u]=True
    c=[0,False]
    if(u==n*m):
        c[1]=True

    if(good[u]=='G'):
        c[0]+=1
    for i in d[u]:
        if(visited[i]==False):
            dr=dfs(i,visited,good,d,n,m)
            c[0]+=dr[0]
            c[1]^=dr[1]
    return c

def inar():
    return [int(k) for k in input().split()]

def main():
    for _ in range(int(input())):
        n,m=map(int,input().split())
        good=[0]*(n*m+1)
        ar=[]
        count=0
        for i in range(n):
            ar.append(list(input()))
        if (n * m == 1 and (ar[0][0]=='G' or ar[0][0]=='.')):
            print('YES')
            continue
        bl=True
        for i in range(n):
            for j in range(m):
                if(ar[i][j]=='G'):
                    if(j+1<m and ar[i][j+1]=='B'):
                        bl=False
                    if(j-1>=0 and ar[i][j-1]=='B'):
                        bl=False
                    if(i-1>=0 and ar[i-1][j]=='B'):
                        bl=False
                    if(i+1<n and ar[i+1][j]=='B'):
                        bl=False
                    if(bl==False):
                        break
            if(bl==False):
                break
        if(bl==False):
            print('No')
            continue
        for i in range(n):
            for j in range(m):
                if(ar[i][j]=='G'):
                    count+=1
                if (ar[i][j] == 'B'):
                    if (j + 1 < m and ar[i][j + 1] == '.'):
                        ar[i][j + 1]='#'
                    if (j - 1 >= 0 and ar[i][j - 1] == '.'):
                        ar[i][j - 1]='#'
                    if (i - 1 >= 0 and ar[i - 1][j] == '.'):
                        ar[i - 1][j]='#'
                    if (i + 1 < n and ar[i + 1][j] == '.'):
                        ar[i + 1][j]='#'

        if(ar[n-1][m-1]=='#' and count>0):
            print('No')
            continue
        d=defaultdict(list)
        ct=0
        for i in range(n):
            for j in range(m):
                ct+=1
                if (ar[i][j] == '.' or ar[i][j]=='G'):
                    if (j + 1 < m and (ar[i][j + 1] == '.' or ar[i][j + 1] == 'G')):
                        d[ct].append(ct+1)
                    if (j - 1 >= 0 and (ar[i][j - 1] == '.' or ar[i][j - 1] == 'G')):
                        d[ct].append(ct-1)
                    if (i - 1 >= 0 and (ar[i - 1][j] == '.' or ar[i - 1][j] == 'G')):
                        d[ct].append(ct-m)
                    if (i + 1 < n and (ar[i + 1][j] == '.' or ar[i + 1][j] == 'G')):
                        d[ct].append(ct+m)

                if(ar[i][j]=='G'):
                    good[ct]='G'

        if(len(d)==0):
            print('Yes')
            continue
        visited=[False]*(n*m+1)
        ans=False
        for i in range(1,n*m+1):
            if(i in d):
                val= dfs(i,visited,good,d,n,m)
                #print(val[0],val[1])
                if(val[0]==count and val[1]==True):
                    ans=True
                    break
        if(ans):
            print('Yes')
        else:
            print('No')

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

"""def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)"""

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""

def dfs(u, visited, good, d, n, m):
    visited[u] = True
    c = [0, False]
    if (u == n * m):
        c[1] = True

    if (good[u] == 'G'):
        c[0] += 1
    for i in d[u]:
        if (visited[i] == False):
            dr = dfs(i, visited, good, d, n, m)
            c[0] += dr[0]
            c[1] ^= dr[1]
    return c

def inar():
    return [int(k) for k in input().split()]

def main():
    for _ in range(int(input())):
        n, m = map(int, input().split())
        good = [0] * (n * m + 1)
        ar = []
        count = 0
        for i in range(n):
            ar.append(list(input()))
        bl = True
        for i in range(n):
            for j in range(m):
                if (ar[i][j] == 'G'):
                    count += 1
                if (ar[i][j] == 'B'):
                    if (j + 1 < m and ar[i][j + 1] == '.'):
                        ar[i][j + 1] = '#'
                    if (j + 1 < m and ar[i][j + 1] == 'G'):
                        bl = False
                        break

                    if (j - 1 >= 0 and ar[i][j - 1] == '.'):
                        ar[i][j - 1] = '#'
                    if (j - 1 >= 0 and ar[i][j - 1] == 'G'):
                        bl = False
                        break

                    if (i - 1 >= 0 and ar[i - 1][j] == '.'):
                        ar[i - 1][j] = '#'
                    if (i - 1 >= 0 and ar[i - 1][j] == 'G'):
                        bl = False
                        break

                    if (i + 1 < n and ar[i + 1][j] == '.'):
                        ar[i + 1][j] = '#'
                    if (i + 1 < n and ar[i + 1][j] == 'G'):
                        bl = False
                        break
        if (bl == False):
            print('No')
            continue
        if (ar[n - 1][m - 1] == '#' and count > 0):
            print('No')
            continue

        d = defaultdict(list)
        ct = 0
        for i in range(n):
            for j in range(m):
                ct += 1
                if (ar[i][j] == '.' or ar[i][j] == 'G'):
                    if (j + 1 < m and (ar[i][j + 1] == '.' or ar[i][j + 1] == 'G')):
                        d[ct].append(ct + 1)
                    if (j - 1 >= 0 and (ar[i][j - 1] == '.' or ar[i][j - 1] == 'G')):
                        d[ct].append(ct - 1)
                    if (i - 1 >= 0 and (ar[i - 1][j] == '.' or ar[i - 1][j] == 'G')):
                        d[ct].append(ct - m)
                    if (i + 1 < n and (ar[i + 1][j] == '.' or ar[i + 1][j] == 'G')):
                        d[ct].append(ct + m)

                if (ar[i][j] == 'G'):
                    good[ct] = 'G'

        if (len(d) == 0 and count == 0):
            print('Yes')
            continue

        visited = [False] * (n * m + 1)
        ans = True
        for i in range(1, n * m + 1):
            if (i in d):
                val = dfs(i, visited, good, d, n, m)
                if (val[0] == count and val[1] == True):
                    ans = True
                    break
                else:
                    ans=False
        if (ans):
            print('Yes')
        else:
            print('No')

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

"""def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)"""

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""

def dfs(u,visited,good,d,n,m):
    visited[u]=True
    c=[0,False]
    if(u==n*m):
        c[1]=True

    if(good[u]=='G'):
        c[0]+=1
    for i in d[u]:
        if(visited[i]==False):
            dr=dfs(i,visited,good,d,n,m)
            c[0]+=dr[0]
            c[1]^=dr[1]
    return c

def inar():
    return [int(k) for k in input().split()]

def main():
    for _ in range(int(input())):
        n,m=map(int,input().split())
        good=[0]*(n*m+1)
        ar=[]
        count=0
        for i in range(n):
            ar.append(list(input()))
        bl=True
        for i in range(n):
            for j in range(m):
                if(ar[i][j]=='G'):
                    if(j+1<m and ar[i][j+1]=='B'):
                        bl=False
                    if(j-1>=0 and ar[i][j-1]=='B'):
                        bl=False
                    if(i-1>=0 and ar[i-1][j]=='B'):
                        bl=False
                    if(i+1<n and ar[i+1][j]=='B'):
                        bl=False
                    if(bl==False):
                        break
            if(bl==False):
                break
        if(bl==False):
            print('No')
            continue
        for i in range(n):
            for j in range(m):
                if(ar[i][j]=='G'):
                    count+=1
                if (ar[i][j] == 'B'):
                    if (j + 1 < m and ar[i][j + 1] == '.'):
                        ar[i][j + 1]='#'
                    if (j - 1 >= 0 and ar[i][j - 1] == '.'):
                        ar[i][j - 1]='#'
                    if (i - 1 >= 0 and ar[i - 1][j] == '.'):
                        ar[i - 1][j]='#'
                    if (i + 1 < n and ar[i + 1][j] == '.'):
                        ar[i + 1][j]='#'

        if(ar[n-1][m-1]=='#' and count>0):
            print('No')
            continue
        d=defaultdict(list)
        ct=0
        for i in range(n):
            for j in range(m):
                ct+=1
                if (ar[i][j] == '.' or ar[i][j]=='G'):
                    if (j + 1 < m and (ar[i][j + 1] == '.' or ar[i][j + 1] == 'G')):
                        d[ct].append(ct+1)
                    if (j - 1 >= 0 and (ar[i][j - 1] == '.' or ar[i][j - 1] == 'G')):
                        d[ct].append(ct-1)
                    if (i - 1 >= 0 and (ar[i - 1][j] == '.' or ar[i - 1][j] == 'G')):
                        d[ct].append(ct-m)
                    if (i + 1 < n and (ar[i + 1][j] == '.' or ar[i + 1][j] == 'G')):
                        d[ct].append(ct+m)

                if(ar[i][j]=='G'):
                    good[ct]='G'

        if(len(d)==0):
            print('Yes')
            continue
        visited=[False]*(n*m+1)
        ans=False
        for i in range(1,n*m+1):
            if(i in d):
                val= dfs(i,visited,good,d,n,m)
                #print(val[0],val[1])
                if(val[0]==count and val[1]==True):
                    ans=True
                    break
        if(ans):
            print('Yes')
        else:
            print('No')

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

"""def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)"""

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""

def dfs(u, visited, good, d, n, m):
    visited[u] = True
    c = [0, False]
    if (u == n * m):
        c[1] = True

    if (good[u] == 'G'):
        c[0] += 1
    for i in d[u]:
        if (visited[i] == False):
            dr = dfs(i, visited, good, d, n, m)
            c[0] += dr[0]
            c[1] ^= dr[1]
    return c

def inar():
    return [int(k) for k in input().split()]

def main():
    for _ in range(int(input())):
        n, m = map(int, input().split())
        good = [0] * (n * m + 1)
        ar = []
        count = 0
        for i in range(n):
            ar.append(list(input()))
        bl = True
        for i in range(n):
            for j in range(m):
                if (ar[i][j] == 'G'):
                    if (j + 1 < m and ar[i][j + 1] == 'B'):
                        bl = False
                    if (j - 1 >= 0 and ar[i][j - 1] == 'B'):
                        bl = False
                    if (i - 1 >= 0 and ar[i - 1][j] == 'B'):
                        bl = False
                    if (i + 1 < n and ar[i + 1][j] == 'B'):
                        bl = False
                    if (bl == False):
                        break
            if (bl == False):
                break
        if (bl == False):
            print('No')
            continue
        for i in range(n):
            for j in range(m):
                if (ar[i][j] == 'G'):
                    count += 1
                if (ar[i][j] == 'B'):
                    if (j + 1 < m and ar[i][j + 1] == '.'):
                        ar[i][j + 1] = '#'
                    if (j - 1 >= 0 and ar[i][j - 1] == '.'):
                        ar[i][j - 1] = '#'
                    if (i - 1 >= 0 and ar[i - 1][j] == '.'):
                        ar[i - 1][j] = '#'
                    if (i + 1 < n and ar[i + 1][j] == '.'):
                        ar[i + 1][j] = '#'

        if (ar[n - 1][m - 1] == '#' and count > 0):
            print('No')
            continue
        d = defaultdict(list)
        ct = 0
        for i in range(n):
            for j in range(m):
                ct += 1
                if (ar[i][j] == '.' or ar[i][j] == 'G'):
                    if (j + 1 < m and (ar[i][j + 1] == '.' or ar[i][j + 1] == 'G')):
                        d[ct].append(ct + 1)
                    if (j - 1 >= 0 and (ar[i][j - 1] == '.' or ar[i][j - 1] == 'G')):
                        d[ct].append(ct - 1)
                    if (i - 1 >= 0 and (ar[i - 1][j] == '.' or ar[i - 1][j] == 'G')):
                        d[ct].append(ct - m)
                    if (i + 1 < n and (ar[i + 1][j] == '.' or ar[i + 1][j] == 'G')):
                        d[ct].append(ct + m)

                if (ar[i][j] == 'G'):
                    good[ct] = 'G'

        # if (len(d) == 0 and count == 0):
        #     print('Yes')
        #     continue
        visited = [False] * (n * m + 1)
        ans = True
        for i in range(1, n * m + 1):
            if (i in d):
                val = dfs(i, visited, good, d, n, m)
                # print(val[0],val[1])
                if (val[0] == count and val[1] == True):
                    ans = True
                    break
                else:
                    ans=False
        if (ans):
            print('Yes')
        else:
            print('No')

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

"""def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)"""

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""

def inar():
    return [int(k) for k in input().split()]

def main():
    for _ in range(int(input())):
        n, m = map(int, input().split())
        good = [0] * (n * m + 1)
        ar = []
        count = 0
        for i in range(n):
            ar.append(list(input()))
        for i in range(n):
            for j in range(m):
                if(ar[i][j]=='B'):
                    if(i-1>=0 and ar[i-1][j]=='.'):
                        ar[i-1][j]='#'
                    if (i + 1 < n and ar[i + 1][j] == '.'):
                        ar[i + 1][j] = '#'
                    if (j - 1 >= 0 and ar[i][j-1] == '.'):
                        ar[i][j-1] = '#'
                    if (j + 1 <m and ar[i][j+1] == '.'):
                        ar[i][j+1] = '#'
        q=[]
        visited=[]
        for i in range(n):
            visited.append([False]*m)

        for i in range(n):
            for j in range(m):
                if(ar[i][j]=='.'):
                    q.append((i,j))
                    visited[i][j]=True
        while(q):
            pos=q.pop(0)
            i=pos[0]
            j=pos[1]
            visited[i][j]=True
            if (i - 1 >= 0 and ar[i - 1][j] != '#' and visited[i-1][j]==False):
                q.append((i-1,j))
            if (i + 1 < n and ar[i + 1][j] != '#' and visited[i+1][j]==False):
                q.append((i+1,j))
            if (j - 1 >= 0 and ar[i][j-1] != '#' and visited[i][j-1]==False):
                q.append((i,j-1))
            if (j + 1 < m and ar[i][j+1] != '#' and visited[i][j+1]==False):
                q.append((i,j+1))

        good=True
        for i in range(n):
            for j in range(m):
                if((ar[i][j]=='G' and visited[i][j]==False) or (ar[i][j]=='B' and visited[i][j]==True)):
                    good=False
                    break
            if(good==False):
                break
        if(good):
            print('Yes')
        else:
            print('No')
BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()


import os
import heapq
import sys
import math
import operator
from collections import defaultdict
from io import BytesIO, IOBase

"""def gcd(a,b):
    if b==0:
        return a
    else:
        return gcd(b,a%b)"""

"""def pw(a,b):
    result=1
    while(b>0):
        if(b%2==1): result*=a
        a*=a
        b//=2
    return result"""

def dfs(u,visited,good,d,n,m):
    visited[u]=True
    c=[0,False]
    if(u==n*m):
        c[1]=True

    if(good[u]=='G'):
        c[0]+=1
    for i in d[u]:
        if(visited[i]==False):
            dr=dfs(i,visited,good,d,n,m)
            c[0]+=dr[0]
            c[1]^=dr[1]
    return c

def inar():
    return [int(k) for k in input().split()]

def main():
    for _ in range(int(input())):
        n,m=map(int,input().split())
        good=[0]*(n*m+1)
        ar=[]
        count=0
        for i in range(n):
            ar.append(list(input()))
        bl=True
        for i in range(n):
            for j in range(m):
                if(ar[i][j]=='G'):
                    if(j+1<m and ar[i][j+1]=='B'):
                        bl=False
                    if(j-1>=0 and ar[i][j-1]=='B'):
                        bl=False
                    if(i-1>=0 and ar[i-1][j]=='B'):
                        bl=False
                    if(i+1<n and ar[i+1][j]=='B'):
                        bl=False
                    if(bl==False):
                        break
            if(bl==False):
                break
        if(bl==False):
            print('No')
            continue
        for i in range(n):
            for j in range(m):
                if(ar[i][j]=='G'):
                    count+=1
                if (ar[i][j] == 'B'):
                    if (j + 1 < m and ar[i][j + 1] == '.'):
                        ar[i][j + 1]='#'
                    if (j - 1 >= 0 and ar[i][j - 1] == '.'):
                        ar[i][j - 1]='#'
                    if (i - 1 >= 0 and ar[i - 1][j] == '.'):
                        ar[i - 1][j]='#'
                    if (i + 1 < n and ar[i + 1][j] == '.'):
                        ar[i + 1][j]='#'

        if(ar[n-1][m-1]=='#' and count>0):
            print('No')
            continue
        d=defaultdict(list)
        ct=0
        for i in range(n):
            for j in range(m):
                ct+=1
                if (ar[i][j] == '.' or ar[i][j]=='G'):
                    if (j + 1 < m and (ar[i][j + 1] == '.' or ar[i][j + 1] == 'G')):
                        d[ct].append(ct+1)
                    if (j - 1 >= 0 and (ar[i][j - 1] == '.' or ar[i][j - 1] == 'G')):
                        d[ct].append(ct-1)
                    if (i - 1 >= 0 and (ar[i - 1][j] == '.' or ar[i - 1][j] == 'G')):
                        d[ct].append(ct-m)
                    if (i + 1 < n and (ar[i + 1][j] == '.' or ar[i + 1][j] == 'G')):
                        d[ct].append(ct+m)

                if(ar[i][j]=='G'):
                    good[ct]='G'

        if(len(d)==0 and count==0):
            print('Yes')
            continue
        visited=[False]*(n*m+1)
        ans=False
        for i in range(1,n*m+1):
            if(i in d):
                val= dfs(i,visited,good,d,n,m)
                #print(val[0],val[1])
                if(val[0]==count and val[1]==True):
                    ans=True
                    break
        if(ans):
            print('Yes')
        else:
            print('No')

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)

class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")

sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

if __name__ == "__main__":
    main()


t = int(input())
for i in range(t):
    n,m = map(int,input().split())
    maze = []
    for j in range(n):
        maze.append(list(input()))

    isReachable = []
    isConsidered = []

    for j in range(n):
        isReachable.append([])
        isConsidered.append([])
        for k in range(m):
            isReachable[j].append(False)
            isConsidered[j].append(False)

    mazeQueue = [(n-1,m-1)]
    mazeQueueIndex = 0
    while True:
        if mazeQueueIndex >= len(mazeQueue):
            break
        currentMazeLocation = mazeQueue[mazeQueueIndex]
        mazeQueueIndex += 1
        isConsidered[currentMazeLocation[0]][currentMazeLocation[1]] = True
        isCurrentLocationReachable = True
        if maze[currentMazeLocation[0]][currentMazeLocation[1]] == "#":
            isCurrentLocationReachable = False
        if currentMazeLocation[0] > 0 and maze[currentMazeLocation[0]-1][currentMazeLocation[1]] == "B":
            isCurrentLocationReachable = False
        if currentMazeLocation[1] > 0 and maze[currentMazeLocation[0]][currentMazeLocation[1]-1] == "B":
            isCurrentLocationReachable = False
        if currentMazeLocation[0] < n - 1 and maze[currentMazeLocation[0]+1][currentMazeLocation[1]] == "B":
            isCurrentLocationReachable = False
        if currentMazeLocation[1] < m - 1 and maze[currentMazeLocation[0]][currentMazeLocation[1]+1] == "B":
            isCurrentLocationReachable = False
        if isCurrentLocationReachable:
            isReachable[currentMazeLocation[0]][currentMazeLocation[1]] = True
            if currentMazeLocation[0] > 0 and isConsidered[currentMazeLocation[0]-1][currentMazeLocation[1]] == False:
                mazeQueue.append((currentMazeLocation[0]-1,currentMazeLocation[1]))
            if currentMazeLocation[1] > 0 and isConsidered[currentMazeLocation[0]][currentMazeLocation[1]-1] == False:
                mazeQueue.append((currentMazeLocation[0],currentMazeLocation[1]-1))
            if currentMazeLocation[0] < n - 1 and isConsidered[currentMazeLocation[0]+1][currentMazeLocation[1]] == False:
                mazeQueue.append((currentMazeLocation[0]+1,currentMazeLocation[1]))
            if currentMazeLocation[1] < m - 1 and isConsidered[currentMazeLocation[0]][currentMazeLocation[1]+1] == False:
                mazeQueue.append((currentMazeLocation[0],currentMazeLocation[1]+1))

    isRescuable = True

    for j in range(n):
        for k in range(m):
            if maze[j][k] == "G" and isReachable[j][k] == False:
                isRescuable = False

    if isRescuable:
        print("Yes")
    else:
        print("No")


t = int(input())
for i in range(t):
    n,m = map(int,input().split())
    maze = []
    for j in range(n):
        maze.append(list(input()))

    isReachable = []
    isConsidered = []

    for j in range(n):
        isReachable.append([])
        isConsidered.append([])
        for k in range(m):
            isReachable[j].append(False)
            isConsidered[j].append(False)

    mazeQueue = [(n-1,m-1)]
    mazeQueueIndex = 0
    while True:
        if mazeQueueIndex >= len(mazeQueue) or mazeQueueIndex > n * m:
            break
        currentMazeLocation = mazeQueue[mazeQueueIndex]
        mazeQueueIndex += 1
        isConsidered[currentMazeLocation[0]][currentMazeLocation[1]] = True
        isCurrentLocationReachable = True
        if maze[currentMazeLocation[0]][currentMazeLocation[1]] == "#":
            isCurrentLocationReachable = False
        if currentMazeLocation[0] > 0 and maze[currentMazeLocation[0]-1][currentMazeLocation[1]] == "B":
            isCurrentLocationReachable = False
        if currentMazeLocation[1] > 0 and maze[currentMazeLocation[0]][currentMazeLocation[1]-1] == "B":
            isCurrentLocationReachable = False
        if currentMazeLocation[0] < n - 1 and maze[currentMazeLocation[0]+1][currentMazeLocation[1]] == "B":
            isCurrentLocationReachable = False
        if currentMazeLocation[1] < m - 1 and maze[currentMazeLocation[0]][currentMazeLocation[1]+1] == "B":
            isCurrentLocationReachable = False
        if isCurrentLocationReachable:
            isReachable[currentMazeLocation[0]][currentMazeLocation[1]] = True
            if currentMazeLocation[0] > 0 and isConsidered[currentMazeLocation[0]-1][currentMazeLocation[1]] == False:
                mazeQueue.append((currentMazeLocation[0]-1,currentMazeLocation[1]))
            if currentMazeLocation[1] > 0 and isConsidered[currentMazeLocation[0]][currentMazeLocation[1]-1] == False:
                mazeQueue.append((currentMazeLocation[0],currentMazeLocation[1]-1))
            if currentMazeLocation[0] < n - 1 and isConsidered[currentMazeLocation[0]+1][currentMazeLocation[1]] == False:
                mazeQueue.append((currentMazeLocation[0]+1,currentMazeLocation[1]))
            if currentMazeLocation[1] < m - 1 and isConsidered[currentMazeLocation[0]][currentMazeLocation[1]+1] == False:
                mazeQueue.append((currentMazeLocation[0],currentMazeLocation[1]+1))

    isRescuable = True

    for j in range(n):
        for k in range(m):
            if maze[j][k] == "G" and isReachable[j][k] == False:
                isRescuable = False

    if isRescuable:
        print("Yes")
    else:
        print("No")


t = int(input())
for i in range(t):
    n,m = map(int,input().split())
    maze = []
    for j in range(n):
        maze.append(list(input()))

    isReachable = []
    isConsidered = []

    for j in range(n):
        isReachable.append([])
        isConsidered.append([])
        for k in range(m):
            isReachable[j].append(False)
            isConsidered[j].append(False)

    mazeQueue = [(n-1,m-1)]
    mazeQueueIndex = 0
    while True:
        if mazeQueueIndex >= len(mazeQueue):
            break
        currentMazeLocation = mazeQueue[mazeQueueIndex]
        mazeQueueIndex += 1
        if isConsidered[currentMazeLocation[0]][currentMazeLocation[1]]:
            continue
        isConsidered[currentMazeLocation[0]][currentMazeLocation[1]] = True
        isCurrentLocationReachable = True
        if maze[currentMazeLocation[0]][currentMazeLocation[1]] == "#":
            isCurrentLocationReachable = False
        if currentMazeLocation[0] > 0 and maze[currentMazeLocation[0]-1][currentMazeLocation[1]] == "B":
            isCurrentLocationReachable = False
        if currentMazeLocation[1] > 0 and maze[currentMazeLocation[0]][currentMazeLocation[1]-1] == "B":
            isCurrentLocationReachable = False
        if currentMazeLocation[0] < n - 1 and maze[currentMazeLocation[0]+1][currentMazeLocation[1]] == "B":
            isCurrentLocationReachable = False
        if currentMazeLocation[1] < m - 1 and maze[currentMazeLocation[0]][currentMazeLocation[1]+1] == "B":
            isCurrentLocationReachable = False
        if isCurrentLocationReachable:
            isReachable[currentMazeLocation[0]][currentMazeLocation[1]] = True
            if currentMazeLocation[0] > 0 and isConsidered[currentMazeLocation[0]-1][currentMazeLocation[1]] == False:
                mazeQueue.append((currentMazeLocation[0]-1,currentMazeLocation[1]))
            if currentMazeLocation[1] > 0 and isConsidered[currentMazeLocation[0]][currentMazeLocation[1]-1] == False:
                mazeQueue.append((currentMazeLocation[0],currentMazeLocation[1]-1))
            if currentMazeLocation[0] < n - 1 and isConsidered[currentMazeLocation[0]+1][currentMazeLocation[1]] == False:
                mazeQueue.append((currentMazeLocation[0]+1,currentMazeLocation[1]))
            if currentMazeLocation[1] < m - 1 and isConsidered[currentMazeLocation[0]][currentMazeLocation[1]+1] == False:
                mazeQueue.append((currentMazeLocation[0],currentMazeLocation[1]+1))

    isRescuable = True

    for j in range(n):
        for k in range(m):
            if maze[j][k] == "G" and isReachable[j][k] == False:
                isRescuable = False

    if isRescuable:
        print("Yes")
    else:
        print("No")


from sys import stdin, gettrace
from collections import deque

if gettrace():
    inputi = input
else:
    def input():
        return next(stdin)[:-1]

    def inputi():
        return stdin.buffer.readline()

def main():
    def solve():

        n,m = map(int, input().split())
        maze = []
        for _ in range(n):
            maze.append(list(input()))
        gcount = 0
        for i in range(n):
            for j in range(m):
                if maze[i][j] == 'B':
                    adj = [(i - 1, j),
                           (i, j - 1),
                           (i + 1, j),
                           (i, j + 1)]
                    for z, w in adj:
                        if 0 <= z < n and 0 <= w < m and maze[z][w] == '.':
                            maze[z][w] = '#'
                elif maze[i][j] == 'G':
                    gcount += 1
        visited = [[False] * m for _ in range(n)]
        if maze[n-1][m-1] =='#':
            if gcount == 0:
                print('Yes')
            else:
                print('No')
            return
        dq = deque()
        dq.append((n-1, m-1))
        while dq:
            x, y = dq.pop()
            visited[x][y] = True
            adj = [(x-1,y), (x, y-1), (x+1, y), (x, y+1)]
            for z, w in adj:
                if 0 <= z < n and 0 <= w < m and not visited[z][w] and maze[z][w] != '#':
                    if maze[z][w] == 'G':
                        gcount -= 1
                    elif maze[z][w] == 'B':
                        print('No')
                        return
                    dq.append((z, w))
        if gcount == 0:
            print("Yes")
        else:
            print('No')

    q = int(inputi())
    for _ in range(q):
        solve()

if __name__ == "__main__":
    main()


from sys import stdin, gettrace
from collections import deque

if gettrace():
    inputi = input
else:
    def input():
        return next(stdin)[:-1]

    def inputi():
        return stdin.buffer.readline()

def main():
    def solve():

        n,m = map(int, input().split())
        maze = []
        for _ in range(n):
            maze.append(list(input()))
        gcount = 0
        for i in range(n):
            for j in range(m):
                if maze[i][j] == 'B':
                    adj = [(i - 1, j),
                           (i, j - 1),
                           (i + 1, j),
                           (i, j + 1)]
                    for z, w in adj:
                        if 0 <= z < n and 0 <= w < m and maze[z][w] == '.':
                            maze[z][w] = '#'
                elif maze[i][j] == 'G':
                    gcount += 1
        visited = [[False] * m for _ in range(n)]
        if maze[n-1][m-1] =='#':
            if gcount == 0:
                print('Yes')
            else:
                print('No')
            return
        dq = deque()
        dq.append((n-1, m-1))
        visited[n-1][m-1] = True
        while dq:
            x, y = dq.pop()
            adj = [(x-1,y), (x, y-1), (x+1, y), (x, y+1)]
            for z, w in adj:
                if 0 <= z < n and 0 <= w < m and not visited[z][w] and maze[z][w] != '#':
                    if maze[z][w] == 'G':
                        gcount -= 1
                    elif maze[z][w] == 'B':
                        print('No')
                        return
                    visited[z][w] = True
                    dq.append((z, w))
        if gcount == 0:
            print("Yes")
        else:
            print('No')

    q = int(inputi())
    for _ in range(q):
        solve()

if __name__ == "__main__":
    main()


from sys import stdin, gettrace
from collections import deque

if gettrace():
    inputi = input
else:
    def input():
        return next(stdin)[:-1]

    def inputi():
        return stdin.buffer.readline()

def main():
    def solve():

        n,m = map(int, input().split())
        maze = []
        for _ in range(n):
            maze.append(list(input()))
        gcount = 0
        for i in range(n):
            for j in range(m):
                if maze[i][j] == 'B':
                    if i > 0 and maze[i-1][j] == '.':
                        maze[i-1][j] = '#'
                    if j > 0 and maze[i][j-1] == '.':
                        maze[i][j-1] = '#'
                    if i < n-1 and maze[i+1][j] == '.':
                        maze[i+1][j] = '#'
                    if j < m-1 and maze[i][j+1] == '.':
                        maze[i][j+1] = '#'
                elif maze[i][j] == 'G':
                    gcount += 1
        visited = [[False] * m for _ in range(n)]
        if maze[n-1][m-1] =='#':
            if gcount == 0:
                print('Yes')
            else:
                print('No')
            return
        dq = deque()
        dq.append((n-1, m-1))
        while dq:
            x, y = dq.pop()
            visited[x][y] = True
            adj = [(x-1,y), (x, y-1), (x+1, y), (x, y+1)]
            for z, w in adj:
                if 0 <= z < n and 0 <= w < m and not visited[z][w] and maze[z][w] != '#':
                    if maze[z][w] == 'G':
                        gcount -= 1
                    elif maze[z][w] == 'B':
                        print('No')
                        return
                    dq.append((z, w))
        if gcount == 0:
            print("Yes")
        else:
            print('No')

    q = int(inputi())
    for _ in range(q):
        solve()

if __name__ == "__main__":
    main()


import java.io.BufferedReader
import java.util.*

fun main() = System.`in`.bufferedReader().run {
    val bw = System.out.bufferedWriter()

    val times = readInt()

    for (time in 0 until times) {
        val r = readInt()
        val c = readInt()

        val m = Array(r) { readLine().toCharArray() }
        var pass = true

        outer@ for (cr in 0 until r) {
            for (cc in 0 until c) {
                if (m[cr][cc] == 'B') {
                    if (cr != 0) {
                        if (m[cr - 1][cc] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr - 1][cc] == '.') {
                            m[cr - 1][cc] = '#'
                        }
                    }
                    if (cc != 0) {
                        if (m[cr][cc - 1] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr][cc - 1] == '.') {
                            m[cr][cc - 1] = '#'
                        }
                    }
                    if (cr != m.lastIndex) {
                        if (m[cr + 1][cc] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr + 1][cc] == '.') {
                            m[cr + 1][cc] = '#'
                        }
                    }
                    if (cc != m.lastIndex) {
                        if (m[cr][cc + 1] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr][cc + 1] == '.') {
                            m[cr][cc + 1] = '#'
                        }
                    }
                }
            }
        }

        pass = pass and (m[r - 1][c - 1] == '.')
        if (pass) {
            val q = ArrayDeque<Pair<Int, Int>>()
            q += Pair(r - 1, c - 1)
            val vis = Array(r) { BooleanArray(c) }

            while (q.isNotEmpty()) {
                val item = q.poll()
                if (vis[item.first][item.second]) {
                    continue
                }
                vis[item.first][item.second] = true

                if (item.first != r - 1 && (m[item.first + 1][item.second] == 'G' || m[item.first + 1][item.second] == '.')) {
                    q += Pair(item.first + 1, item.second)
                }

                if (item.second != c - 1 && (m[item.first][item.second + 1] == 'G' || m[item.first][item.second + 1] == '.')) {
                    q += Pair(item.first, item.second + 1)
                }

                if (item.first != 0 && (m[item.first - 1][item.second] == 'G' || m[item.first - 1][item.second] == '.')) {
                    q += Pair(item.first - 1, item.second)
                }

                if (item.second != 0 && (m[item.first][item.second - 1] == 'G' || m[item.first][item.second - 1] == '.')) {
                    q += Pair(item.first, item.second - 1)
                }
            }

            p@ for (cr in 0 until r) {
                for (cc in 0 until c) {
                    if (m[cr][cc] == 'G' && !vis[cr][cc]) {
                        pass = false
                        break@p
                    }
                }
            }
        }

        bw.append(if (pass) "Yes" else "No")
        bw.newLine()
    }

    bw.close()
}

private const val SPACE_INT = ' '.toInt()
private const val ZERO_INT = '0'.toInt()
private const val CR_INT = '\r'.toInt()

@Suppress("DuplicatedCode")
private fun BufferedReader.readInt(): Int {
    var ret = read()
    while (ret <= SPACE_INT) {
        ret = read()
    }
    val neg = ret == '-'.toInt()
    if (neg) {
        ret = read()
    }
    ret -= ZERO_INT
    var read = read()
    while (read >= ZERO_INT) {
        ret *= 10
        ret += read - ZERO_INT
        read = read()
    }
    if (read == CR_INT) {
        read()
    }
    return if (neg) -ret else ret
}


import java.io.BufferedReader
import java.util.*

fun main() = System.`in`.bufferedReader().run {
    val bw = System.out.bufferedWriter()

    val times = readInt()

    for (time in 0 until times) {
        val r = readInt()
        val c = readInt()

        val m = Array(r) { readLine().toCharArray() }
        if (!m.any { it.any { ch -> ch >= 'B' } }) {
            bw.append("Yes")
        } else if (!m.any { it.contains('G') }) {
            bw.append("Yes")
        } else if ((r > 1 && m[r - 2][c - 1] == 'B') || (c > 1 && m[r - 1][c - 2] == 'B')) {
            bw.append("No")
        } else {
            var pass = true

            outer@ for (cr in 0 until r) {
                for (cc in 0 until c) {
                    if (m[cr][cc] == 'B') {
                        if (cr != 0) {
                            if (m[cr - 1][cc] == 'G') {
                                pass = false
                                break@outer
                            } else if (m[cr - 1][cc] == '.') {
                                m[cr - 1][cc] = '#'
                            }
                        }
                        if (cc != 0) {
                            if (m[cr][cc - 1] == 'G') {
                                pass = false
                                break@outer
                            } else if (m[cr][cc - 1] == '.') {
                                m[cr][cc - 1] = '#'
                            }
                        }
                        if (cr != m.lastIndex) {
                            if (m[cr + 1][cc] == 'G') {
                                pass = false
                                break@outer
                            } else if (m[cr + 1][cc] == '.') {
                                m[cr + 1][cc] = '#'
                            }
                        }
                        if (cc != m.lastIndex) {
                            if (m[cr][cc + 1] == 'G') {
                                pass = false
                                break@outer
                            } else if (m[cr][cc + 1] == '.') {
                                m[cr][cc + 1] = '#'
                            }
                        }
                    }
                }
            }

            if (pass) {
                val q = ArrayDeque<Pair<Int, Int>>()
                q += Pair(r - 1, c - 1)
                val vis = Array(r) { BooleanArray(c) }

                while (q.isNotEmpty()) {
                    val item = q.poll()
                    if (vis[item.first][item.second]) {
                        continue
                    }
                    vis[item.first][item.second] = true

                    if (item.first != r - 1 && (m[item.first + 1][item.second] == 'G' || m[item.first + 1][item.second] == '.')) {
                        q += Pair(item.first + 1, item.second)
                    }

                    if (item.second != c - 1 && (m[item.first][item.second + 1] == 'G' || m[item.first][item.second + 1] == '.')) {
                        q += Pair(item.first, item.second + 1)
                    }

                    if (item.first != 0 && (m[item.first - 1][item.second] == 'G' || m[item.first - 1][item.second] == '.')) {
                        q += Pair(item.first - 1, item.second)
                    }

                    if (item.second != 0 && (m[item.first][item.second - 1] == 'G' || m[item.first][item.second - 1] == '.')) {
                        q += Pair(item.first, item.second - 1)
                    }
                }

                p@for (cr in 0 until r) {
                    for (cc in 0 until c) {
                        if (m[cr][cc] == 'G' && !vis[cr][cc]) {
                            pass = false
                            break@p
                        }
                    }
                }
            }

            bw.append(if (pass) "Yes" else "No")
        }
        bw.newLine()
    }

    bw.close()
}

private const val SPACE_INT = ' '.toInt()
private const val ZERO_INT = '0'.toInt()
private const val CR_INT = '\r'.toInt()

@Suppress("DuplicatedCode")
private fun BufferedReader.readInt(): Int {
    var ret = read()
    while (ret <= SPACE_INT) {
        ret = read()
    }
    val neg = ret == '-'.toInt()
    if (neg) {
        ret = read()
    }
    ret -= ZERO_INT
    var read = read()
    while (read >= ZERO_INT) {
        ret *= 10
        ret += read - ZERO_INT
        read = read()
    }
    if (read == CR_INT) {
        read()
    }
    return if (neg) -ret else ret
}


import java.io.BufferedReader
import java.util.*

fun main() = System.`in`.bufferedReader().run {
    val bw = System.out.bufferedWriter()

    val times = readLine().toInt()

    for (time in 0 until times) {
        val (r, c) = readLine().split(' ').map(String::toInt)

        val m = Array(r) { readLine().substring(0, c).toCharArray() }
        var pass = true

        if (m.none { it.contains('G') }) {
            bw.append("Yes")
            bw.newLine()
            continue
        }

        outer@ for (cr in 0 until r) {
            for (cc in 0 until c) {
                if (m[cr][cc] == 'B') {
                    if (cr != 0) {
                        if (m[cr - 1][cc] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr - 1][cc] == '.') {
                            m[cr - 1][cc] = '#'
                        }
                    }
                    if (cc != 0) {
                        if (m[cr][cc - 1] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr][cc - 1] == '.') {
                            m[cr][cc - 1] = '#'
                        }
                    }
                    if (cr != m.lastIndex) {
                        if (m[cr + 1][cc] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr + 1][cc] == '.') {
                            m[cr + 1][cc] = '#'
                        }
                    }
                    if (cc != m.lastIndex) {
                        if (m[cr][cc + 1] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr][cc + 1] == '.') {
                            m[cr][cc + 1] = '#'
                        }
                    }
                }
            }
        }

        pass = pass and (m[r - 1][c - 1] == '.')
        if (pass) {
            val q = ArrayDeque<Pair<Int, Int>>()
            q += Pair(r - 1, c - 1)
            val vis = Array(r) { BooleanArray(c) }

            while (q.isNotEmpty()) {
                val item = q.poll()
                if (vis[item.first][item.second]) {
                    continue
                }
                vis[item.first][item.second] = true

                if (item.first != r - 1 && (m[item.first + 1][item.second] == 'G' || m[item.first + 1][item.second] == '.')) {
                    q += Pair(item.first + 1, item.second)
                }

                if (item.second != c - 1 && (m[item.first][item.second + 1] == 'G' || m[item.first][item.second + 1] == '.')) {
                    q += Pair(item.first, item.second + 1)
                }

                if (item.first != 0 && (m[item.first - 1][item.second] == 'G' || m[item.first - 1][item.second] == '.')) {
                    q += Pair(item.first - 1, item.second)
                }

                if (item.second != 0 && (m[item.first][item.second - 1] == 'G' || m[item.first][item.second - 1] == '.')) {
                    q += Pair(item.first, item.second - 1)
                }
            }

            p@ for (cr in 0 until r) {
                for (cc in 0 until c) {
                    if (m[cr][cc] == 'G' && !vis[cr][cc]) {
                        pass = false
                        break@p
                    }
                }
            }
        }

        bw.append(if (pass) "Yes" else "No")
        bw.newLine()
    }

    bw.close()
}


import java.io.BufferedReader
import java.util.*

fun main() = System.`in`.bufferedReader().run {
    val bw = System.out.bufferedWriter()

    val times = readLine().toInt()

    for (time in 0 until times) {
        val (r, c) = readLine().split(' ').map(String::toInt)

        val m = Array(r) { readLine().substring(0, c).toCharArray() }
        var pass = true

        if (m.none { it.contains('G') }) {
            bw.append("Yes")
            bw.newLine()
            continue
        }

        outer@ for (cr in 0 until r) {
            for (cc in 0 until c) {
                if (m[cr][cc] == 'B') {
                    if (cr != 0) {
                        if (m[cr - 1][cc] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr - 1][cc] == '.') {
                            m[cr - 1][cc] = '#'
                        }
                    }
                    if (cc != 0) {
                        if (m[cr][cc - 1] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr][cc - 1] == '.') {
                            m[cr][cc - 1] = '#'
                        }
                    }
                    if (cr != r - 1) {
                        if (m[cr + 1][cc] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr + 1][cc] == '.') {
                            m[cr + 1][cc] = '#'
                        }
                    }
                    if (cc != c - 1) {
                        if (m[cr][cc + 1] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr][cc + 1] == '.') {
                            m[cr][cc + 1] = '#'
                        }
                    }
                }
            }
        }

        pass = pass and (m[r - 1][c - 1] == '.')
        if (pass) {
            val q = ArrayDeque<Pair<Int, Int>>()
            q += Pair(r - 1, c - 1)
            val vis = Array(r) { BooleanArray(c) }

            while (q.isNotEmpty()) {
                val item = q.poll()
                if (vis[item.first][item.second]) {
                    continue
                }
                vis[item.first][item.second] = true

                if (item.first != r - 1 && (m[item.first + 1][item.second] == 'G' || m[item.first + 1][item.second] == '.')) {
                    q += Pair(item.first + 1, item.second)
                }

                if (item.second != c - 1 && (m[item.first][item.second + 1] == 'G' || m[item.first][item.second + 1] == '.')) {
                    q += Pair(item.first, item.second + 1)
                }

                if (item.first != 0 && (m[item.first - 1][item.second] == 'G' || m[item.first - 1][item.second] == '.')) {
                    q += Pair(item.first - 1, item.second)
                }

                if (item.second != 0 && (m[item.first][item.second - 1] == 'G' || m[item.first][item.second - 1] == '.')) {
                    q += Pair(item.first, item.second - 1)
                }
            }

            p@ for (cr in 0 until r) {
                for (cc in 0 until c) {
                    if (m[cr][cc] == 'G' && !vis[cr][cc]) {
                        pass = false
                        break@p
                    }
                }
            }
        }

        bw.append(if (pass) "Yes" else "No")
        bw.newLine()
    }

    bw.close()
}


import java.io.BufferedReader
import java.util.*

fun main() = System.`in`.bufferedReader().run {
    val bw = System.out.bufferedWriter()

    val times = readLine().toInt()

    for (time in 0 until times) {
        val (r, c) = readLine().split(' ').map(String::toInt)

        val m = Array(r) { readLine().toCharArray() }
        var pass = true

        if (m.none { it.contains('G') }) {
            bw.append("Yes")
            bw.newLine()
            continue
        }

        outer@ for (cr in 0 until r) {
            for (cc in 0 until c) {
                if (m[cr][cc] == 'B') {
                    if (cr != 0) {
                        if (m[cr - 1][cc] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr - 1][cc] == '.') {
                            m[cr - 1][cc] = '#'
                        }
                    }
                    if (cc != 0) {
                        if (m[cr][cc - 1] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr][cc - 1] == '.') {
                            m[cr][cc - 1] = '#'
                        }
                    }
                    if (cr != m.lastIndex) {
                        if (m[cr + 1][cc] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr + 1][cc] == '.') {
                            m[cr + 1][cc] = '#'
                        }
                    }
                    if (cc != m.lastIndex) {
                        if (m[cr][cc + 1] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr][cc + 1] == '.') {
                            m[cr][cc + 1] = '#'
                        }
                    }
                }
            }
        }

        pass = pass and (m[r - 1][c - 1] == '.')
        if (pass) {
            val q = ArrayDeque<Pair<Int, Int>>()
            q += Pair(r - 1, c - 1)
            val vis = Array(r) { BooleanArray(c) }

            while (q.isNotEmpty()) {
                val item = q.poll()
                if (vis[item.first][item.second]) {
                    continue
                }
                vis[item.first][item.second] = true

                if (item.first != r - 1 && (m[item.first + 1][item.second] == 'G' || m[item.first + 1][item.second] == '.')) {
                    q += Pair(item.first + 1, item.second)
                }

                if (item.second != c - 1 && (m[item.first][item.second + 1] == 'G' || m[item.first][item.second + 1] == '.')) {
                    q += Pair(item.first, item.second + 1)
                }

                if (item.first != 0 && (m[item.first - 1][item.second] == 'G' || m[item.first - 1][item.second] == '.')) {
                    q += Pair(item.first - 1, item.second)
                }

                if (item.second != 0 && (m[item.first][item.second - 1] == 'G' || m[item.first][item.second - 1] == '.')) {
                    q += Pair(item.first, item.second - 1)
                }
            }

            p@ for (cr in 0 until r) {
                for (cc in 0 until c) {
                    if (m[cr][cc] == 'G' && !vis[cr][cc]) {
                        pass = false
                        break@p
                    }
                }
            }
        }

        bw.append(if (pass) "Yes" else "No")
        bw.newLine()
    }

    bw.close()
}


import java.io.BufferedReader
import java.util.ArrayDeque

fun main() = System.`in`.bufferedReader().run {
    val bw = System.out.bufferedWriter()

    val times = readInt()

    for (time in 0 until times) {
        val r = readInt()
        val c = readInt()

        val m = Array(r) { readLine().toCharArray() }
        if (!m.any { it.any { ch -> ch >= 'B' } }) {
            bw.append("Yes")
        } else if (!m.any { it.contains('B') } || !m.any { it.contains('G') }) {
            bw.append("Yes")
        } else if ((r > 1 && m[r - 2][c - 1] == 'B') || (c > 1 && m[r - 1][c - 2] == 'B')) {
            bw.append("No")
        } else {
            val reps = Array(r) { cr -> Array(c) { cc -> Pair(cr, cc) } }
            var pass = true

            outer@for (cr in 0 until r) {
                for (cc in 0 until c) {
                    if (m[cr][cc] == 'B') {
                        if (cr != 0) {
                            if (m[cr - 1][cc] == 'G') {
                                pass = false
                                break@outer
                            } else if (m[cr - 1][cc] == '.') {
                                m[cr - 1][cc] = '#'
                            }
                        }
                        if (cc != 0) {
                            if (m[cr][cc - 1] == 'G') {
                                pass = false
                                break@outer
                            } else if (m[cr][cc - 1] == '.') {
                                m[cr][cc - 1] = '#'
                            }
                        }
                        if (cr != m.lastIndex) {
                            if (m[cr + 1][cc] == 'G') {
                                pass = false
                                break@outer
                            } else if (m[cr + 1][cc] == '.') {
                                m[cr + 1][cc] = '#'
                            }
                        }
                        if (cc != m.lastIndex) {
                            if (m[cr][cc + 1] == 'G') {
                                pass = false
                                break@outer
                            } else if (m[cr][cc + 1] == '.') {
                                m[cr][cc + 1] = '#'
                            }
                        }
                    } else if (m[cr][cc] == 'G') {
                        if (cr != 0 && m[cr - 1][cc] == 'G') {
                            reps[cr][cc] = reps[cr - 1][cc]
                            if (cc != 0 && m[cr][cc - 1] == 'G') {
                                var cRep = reps[cr][cc - 1]
                                while (reps[cRep.first][cRep.second] != cRep) {
                                    cRep = reps[cRep.first][cRep.second]
                                }
                                reps[cRep.first][cRep.second] = reps[cr - 1][cc]
                            }
                        } else if (cc != 0 && m[cr][cc - 1] == 'G') {
                            reps[cr][cc] = reps[cr][cc - 1]
                        }
                    }
                }
            }

            if (pass) {
                val checks = HashSet<Pair<Int, Int>>()
                for (cr in 0 until r) {
                    for (cc in 0 until c) {
                        if (m[cr][cc] == 'G') {
                            var cRep = reps[cr][cc]
                            while (reps[cRep.first][cRep.second] != cRep) {
                                cRep = reps[cRep.first][cRep.second]
                            }
                            checks += cRep
                        }
                    }
                }

                for (startPos in checks) {
                    val q = ArrayDeque<Pair<Int, Int>>()
                    q += startPos
                    val vis = Array(r) { BooleanArray(c) }

                    var localPass = false
                    while (q.isNotEmpty()) {
                        val item = q.poll()

                        if (item.first == r - 1 && item.second == c - 1) {
                            localPass = true
                            break
                        }

                        if (item.first != r - 1 && !vis[item.first + 1][item.second] && (m[item.first + 1][item.second] == 'G' || m[item.first + 1][item.second] == '.')) {
                            vis[item.first + 1][item.second] = true
                            q += Pair(item.first + 1, item.second)
                        }

                        if (item.second != c - 1 && !vis[item.first][item.second + 1] && (m[item.first][item.second + 1] == 'G' || m[item.first][item.second + 1] == '.')) {
                            vis[item.first][item.second + 1] = true
                            q += Pair(item.first, item.second + 1)
                        }

                        if (item.first != 0 && !vis[item.first - 1][item.second] && (m[item.first - 1][item.second] == 'G' || m[item.first - 1][item.second] == '.')) {
                            vis[item.first - 1][item.second] = true
                            q += Pair(item.first - 1, item.second)
                        }

                        if (item.second != 0 && !vis[item.first][item.second - 1] && (m[item.first][item.second - 1] == 'G' || m[item.first][item.second - 1] == '.')) {
                            vis[item.first][item.second - 1] = true
                            q += Pair(item.first, item.second - 1)
                        }
                    }

                    if (!localPass) {
                        pass = false
                        break
                    }
                }
            }

            bw.append(if (pass) "Yes" else "No")
        }
        bw.newLine()
    }

    bw.close()
}

private const val SPACE_INT = ' '.toInt()
private const val ZERO_INT = '0'.toInt()
private const val CR_INT = '\r'.toInt()

@Suppress("DuplicatedCode")
private fun BufferedReader.readInt(): Int {
    var ret = read()
    while (ret <= SPACE_INT) {
        ret = read()
    }
    val neg = ret == '-'.toInt()
    if (neg) {
        ret = read()
    }
    ret -= ZERO_INT
    var read = read()
    while (read >= ZERO_INT) {
        ret *= 10
        ret += read - ZERO_INT
        read = read()
    }
    if (read == CR_INT) {
        read()
    }
    return if (neg) -ret else ret
}

@Suppress("DuplicatedCode")
private fun BufferedReader.readLong(): Long {
    var ret = read().toLong()
    while (ret <= SPACE_INT) {
        ret = read().toLong()
    }
    val neg = ret == '-'.toLong()
    if (neg) {
        ret = read().toLong()
    }
    ret -= ZERO_INT
    var read = read()
    while (read >= ZERO_INT) {
        ret *= 10
        ret += read - ZERO_INT
        read = read()
    }
    if (read == CR_INT) {
        read()
    }
    return if (neg) -ret else ret
}

@Suppress("DuplicatedCode")
private fun BufferedReader.readWord(): String {
    var ret = read()
    while (ret <= SPACE_INT && ret != -1) {
        ret = read()
    }
    if (ret == -1) {
        return ""
    }
    var cb = CharArray(32)
    var idx = 0
    while (ret > SPACE_INT) {
        if (idx == cb.size) {
            cb = cb.copyOf(cb.size shl 1)
        }
        cb[idx++] = ret.toChar()
        ret = read()
    }
    if (ret == CR_INT) {
        read()
    }
    return String(cb, 0, idx)
}


import java.io.BufferedReader
import java.util.ArrayDeque

fun main() = System.`in`.bufferedReader().run {
    val bw = System.out.bufferedWriter()

    val times = readInt()

    for (time in 0 until times) {
        val r = readInt()
        val c = readInt()

        val m = Array(r) { readLine().toCharArray() }
        if (!m.any { it.any { ch -> ch >= 'B' } }) {
            bw.append("Yes")
        } else if (!m.any { it.contains('G') }) {
            bw.append("Yes")
        } else if ((r > 1 && m[r - 2][c - 1] == 'B') || (c > 1 && m[r - 1][c - 2] == 'B')) {
            bw.append("No")
        } else {
            val reps = Array(r) { cr -> Array(c) { cc -> Pair(cr, cc) } }
            var pass = true

            outer@for (cr in 0 until r) {
                for (cc in 0 until c) {
                    if (m[cr][cc] == 'B') {
                        if (cr != 0) {
                            if (m[cr - 1][cc] == 'G') {
                                pass = false
                                break@outer
                            } else if (m[cr - 1][cc] == '.') {
                                m[cr - 1][cc] = '#'
                            }
                        }
                        if (cc != 0) {
                            if (m[cr][cc - 1] == 'G') {
                                pass = false
                                break@outer
                            } else if (m[cr][cc - 1] == '.') {
                                m[cr][cc - 1] = '#'
                            }
                        }
                        if (cr != m.lastIndex) {
                            if (m[cr + 1][cc] == 'G') {
                                pass = false
                                break@outer
                            } else if (m[cr + 1][cc] == '.') {
                                m[cr + 1][cc] = '#'
                            }
                        }
                        if (cc != m.lastIndex) {
                            if (m[cr][cc + 1] == 'G') {
                                pass = false
                                break@outer
                            } else if (m[cr][cc + 1] == '.') {
                                m[cr][cc + 1] = '#'
                            }
                        }
                    } else if (m[cr][cc] == 'G') {
                        if (cr != 0 && m[cr - 1][cc] == 'G') {
                            reps[cr][cc] = reps[cr - 1][cc]
                            if (cc != 0 && m[cr][cc - 1] == 'G') {
                                var cRep = reps[cr][cc - 1]
                                while (reps[cRep.first][cRep.second] != cRep) {
                                    cRep = reps[cRep.first][cRep.second]
                                }
                                reps[cRep.first][cRep.second] = reps[cr - 1][cc]
                            }
                        } else if (cc != 0 && m[cr][cc - 1] == 'G') {
                            reps[cr][cc] = reps[cr][cc - 1]
                        }
                    }
                }
            }

            if (pass) {
                val checks = HashSet<Pair<Int, Int>>()
                for (cr in 0 until r) {
                    for (cc in 0 until c) {
                        if (m[cr][cc] == 'G') {
                            var cRep = reps[cr][cc]
                            while (reps[cRep.first][cRep.second] != cRep) {
                                cRep = reps[cRep.first][cRep.second]
                            }
                            checks += cRep
                        }
                    }
                }

                for (startPos in checks) {
                    val q = ArrayDeque<Pair<Int, Int>>()
                    q += startPos
                    val vis = Array(r) { BooleanArray(c) }

                    var localPass = false
                    while (q.isNotEmpty()) {
                        val item = q.poll()

                        if (item.first == r - 1 && item.second == c - 1) {
                            localPass = true
                            break
                        }

                        if (item.first != r - 1 && !vis[item.first + 1][item.second] && (m[item.first + 1][item.second] == 'G' || m[item.first + 1][item.second] == '.')) {
                            vis[item.first + 1][item.second] = true
                            q += Pair(item.first + 1, item.second)
                        }

                        if (item.second != c - 1 && !vis[item.first][item.second + 1] && (m[item.first][item.second + 1] == 'G' || m[item.first][item.second + 1] == '.')) {
                            vis[item.first][item.second + 1] = true
                            q += Pair(item.first, item.second + 1)
                        }

                        if (item.first != 0 && !vis[item.first - 1][item.second] && (m[item.first - 1][item.second] == 'G' || m[item.first - 1][item.second] == '.')) {
                            vis[item.first - 1][item.second] = true
                            q += Pair(item.first - 1, item.second)
                        }

                        if (item.second != 0 && !vis[item.first][item.second - 1] && (m[item.first][item.second - 1] == 'G' || m[item.first][item.second - 1] == '.')) {
                            vis[item.first][item.second - 1] = true
                            q += Pair(item.first, item.second - 1)
                        }
                    }

                    if (!localPass) {
                        pass = false
                        break
                    }
                }
            }

            bw.append(if (pass) "Yes" else "No")
        }
        bw.newLine()
    }

    bw.close()
}

private const val SPACE_INT = ' '.toInt()
private const val ZERO_INT = '0'.toInt()
private const val CR_INT = '\r'.toInt()

@Suppress("DuplicatedCode")
private fun BufferedReader.readInt(): Int {
    var ret = read()
    while (ret <= SPACE_INT) {
        ret = read()
    }
    val neg = ret == '-'.toInt()
    if (neg) {
        ret = read()
    }
    ret -= ZERO_INT
    var read = read()
    while (read >= ZERO_INT) {
        ret *= 10
        ret += read - ZERO_INT
        read = read()
    }
    if (read == CR_INT) {
        read()
    }
    return if (neg) -ret else ret
}


import java.io.BufferedReader
import java.util.*

fun main() = System.`in`.bufferedReader().run {
    val bw = System.out.bufferedWriter()

    val times = readInt()

    for (time in 0 until times) {
        val r = readInt()
        val c = readInt()

        val m = Array(r) { readLine().toCharArray() }
        var pass = true

        if (m.none { it.contains('G') }) {
            bw.append("Yes")
            bw.newLine()
            continue
        }

        outer@ for (cr in 0 until r) {
            for (cc in 0 until c) {
                if (m[cr][cc] == 'B') {
                    if (cr != 0) {
                        if (m[cr - 1][cc] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr - 1][cc] == '.') {
                            m[cr - 1][cc] = '#'
                        }
                    }
                    if (cc != 0) {
                        if (m[cr][cc - 1] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr][cc - 1] == '.') {
                            m[cr][cc - 1] = '#'
                        }
                    }
                    if (cr != m.lastIndex) {
                        if (m[cr + 1][cc] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr + 1][cc] == '.') {
                            m[cr + 1][cc] = '#'
                        }
                    }
                    if (cc != m.lastIndex) {
                        if (m[cr][cc + 1] == 'G') {
                            pass = false
                            break@outer
                        } else if (m[cr][cc + 1] == '.') {
                            m[cr][cc + 1] = '#'
                        }
                    }
                }
            }
        }

        pass = pass and (m[r - 1][c - 1] == '.')
        if (pass) {
            val q = ArrayDeque<Pair<Int, Int>>()
            q += Pair(r - 1, c - 1)
            val vis = Array(r) { BooleanArray(c) }

            while (q.isNotEmpty()) {
                val item = q.poll()
                if (vis[item.first][item.second]) {
                    continue
                }
                vis[item.first][item.second] = true

                if (item.first != r - 1 && (m[item.first + 1][item.second] == 'G' || m[item.first + 1][item.second] == '.')) {
                    q += Pair(item.first + 1, item.second)
                }

                if (item.second != c - 1 && (m[item.first][item.second + 1] == 'G' || m[item.first][item.second + 1] == '.')) {
                    q += Pair(item.first, item.second + 1)
                }

                if (item.first != 0 && (m[item.first - 1][item.second] == 'G' || m[item.first - 1][item.second] == '.')) {
                    q += Pair(item.first - 1, item.second)
                }

                if (item.second != 0 && (m[item.first][item.second - 1] == 'G' || m[item.first][item.second - 1] == '.')) {
                    q += Pair(item.first, item.second - 1)
                }
            }

            p@ for (cr in 0 until r) {
                for (cc in 0 until c) {
                    if (m[cr][cc] == 'G' && !vis[cr][cc]) {
                        pass = false
                        break@p
                    }
                }
            }
        }

        bw.append(if (pass) "Yes" else "No")
        bw.newLine()
    }

    bw.close()
}

private const val SPACE_INT = ' '.toInt()
private const val ZERO_INT = '0'.toInt()
private const val CR_INT = '\r'.toInt()

@Suppress("DuplicatedCode")
private fun BufferedReader.readInt(): Int {
    var ret = read()
    while (ret <= SPACE_INT) {
        ret = read()
    }
    val neg = ret == '-'.toInt()
    if (neg) {
        ret = read()
    }
    ret -= ZERO_INT
    var read = read()
    while (read >= ZERO_INT) {
        ret *= 10
        ret += read - ZERO_INT
        read = read()
    }
    if (read == CR_INT) {
        read()
    }
    return if (neg) -ret else ret
}


import java.util.*

@JvmField
val INPUT = System.`in`
@JvmField
val OUTPUT = System.out

@JvmField
val _reader = INPUT.bufferedReader()
fun readLine(): String? = _reader.readLine()
fun readLn() = _reader.readLine()!!

@JvmField
var _tokenizer: StringTokenizer = StringTokenizer("")
fun read(): String {
    while (_tokenizer.hasMoreTokens().not()) _tokenizer = StringTokenizer(_reader.readLine() ?: return "", " ")
    return _tokenizer.nextToken()
}

fun readIntArray(n: Int) = IntArray(n) { read().toInt() }
fun readLongArray(n: Int) = LongArray(n) { read().toLong() }

fun readInt() = read().toInt()
fun readLong() = read().toLong()

fun main() {
    repeat(readInt()) {
        val (n, m) = readIntArray(2)
        val maze = mutableListOf<MutableList<Char>>()
        var badCount = 0
        var goodCount = 0
        for (i in 0 until n) {
            val line = read()
            maze.add(mutableListOf())
            for (c in line) {
                maze[i].add(c)
                if (c == 'B') {
                    badCount++
                } else if (c == 'G') {
                    goodCount++
                }
            }
        }

        fun isValid(i: Int, j: Int): Boolean {
            return i >= 0 && j >= 0 && i < n && j < m
        }

        val dx = listOf(-1, 1, 0, 0)
        val dy = listOf(0, 0, -1, 1)

        for (i in 0 until n) {
            for (j in 0 until m) {
                if (maze[i][j] == 'B') {
                    for (k in dx.indices) {
                        val newI = i + dx[k]
                        val newJ = j + dy[k]

                        if (isValid(newI, newJ) && maze[newI][newJ] == '.') {
                            maze[newI][newJ] = '#'
                        }
                    }
                }
            }
        }

        val used = Array(n) {BooleanArray(m) {false} }

        fun dfs(i: Int, j: Int) {
            used[i][j] = true

            for (k in dx.indices) {
                val newI = i + dx[k]
                val newJ = j + dy[k]

                if (isValid(newI, newJ) && !used[newI][newJ] && maze[newI][newJ] != '#') {
                    dfs(newI, newJ)
                }
            }
        }

        if (maze[n - 1][m - 1] != '#') {
            dfs(n - 1, m - 1)
        }

        var visitedGoodCount = 0
        var visitedBadCount = 0

        for (i in 0 until n) {
            for (j in 0 until m) {
                if (used[i][j]) {
                    if (maze[i][j] == 'G') {
                        visitedGoodCount++
                    } else if (maze[i][j] == 'B') {
                        visitedBadCount++
                    }
                }
            }
        }

        if (visitedBadCount > 0 || visitedGoodCount != goodCount) {
            println("NO")
        } else {
            println("YES")
        }

    }
}


import java.lang.Math.pow
import java.lang.String.format
import java.util.*
import kotlin.math.*
import kotlin.system.exitProcess

private fun readLn() = readLine()!! // string line
private fun readStrings() = readLn().split(" ") // list of strings
private fun readLong() = readLn().toLong()
private fun readLongs() = readStrings().map { it.toLong() } // list of ints
private fun readInt() = readLn().toInt() // single int
private fun readInts() = readStrings().map { it.toInt() } // list of ints

var maze = Array(0) {Array(0) {0} }
var n = 0
var m = 0
fun main() {
    val t = readInt()

    for (cases in 0 until t) {
        solve()
    }
}

fun solve() {
    val (n1,m1) = readInts(); n = n1; m = m1
    maze = Array(n) {Array(m) {0} }

    for (r in 0 until n) {
        var row = readLn()
        for (c in row.indices) {
            if (row[c] == '.') maze[r][c] = 0
            if (row[c] == 'G') maze[r][c] = 1
            if (row[c] == 'B') maze[r][c] = 2
            if (row[c] == '#') maze[r][c] = 3
        }
    }

    for (r in 0 until n) {
        for (c in 0 until m) {
            if (maze[r][c] != 2) continue
            // Block bad
            if (!block(r-1, c) ||
                !block(r+1, c) ||
                !block(r, c-1) ||
                !block(r, c+1)) {
                println("No"); return
            }
        }
    }

    if (!dfs(n-1, m-1)) {println("No"); return}

//    println("Here")

    for (r in 0 until n) {
        for (c in 0 until m) {
            if (maze[r][c] == 1) {println("No"); return}
        }
    }
    println("YES")
}

fun dfs(r: Int, c: Int): Boolean {
    if (r < 0 || c < 0 || r >= n || c >= m) return true
    val cur = maze[r][c]
    if (cur == 2) return false
    if (cur == 5 || cur == 3) return true

    maze[r][c] = 5
    return dfs(r-1,c) && dfs(r+1,c) && dfs(r,c-1) && dfs(r,c+1)
}

fun block(r: Int, c: Int): Boolean {
    if (r < 0 || c < 0 || r >= n || c >= m) return true
    if (maze[r][c] == 0) { // empty
        maze[r][c] = 3
        return true
    }
    return maze[r][c] != 1 // not G, B and # is okay.
}