def pathExists(i,j,n,m):
    if i==n and j==m and dp[i][j]!=False:
        return True
    if dp[i][j]!=None:
        return dp[i][j]

    visited.add((i,j))
    x,y,z,w = False,False,False,False
    if (i-1)>=1:
        if (i-1,j) not in visited:
            x = pathExists(i-1,j,n,m)
    if x==True:
        dp[i][j]=True
        return True
    if (j-1)>=1:
        if (i,j-1) not in visited:
            y = pathExists(i,j-1,n,m)
    if y==True:
        dp[i][j]=True
        return True
    if (j+1)<=m:
        if (i,j+1) not in visited:
            z = pathExists(i,j+1,n,m)
    if z==True:
        dp[i][j]=True
        return True
    if (i+1)<=n:
        if (i+1,j) not in visited:
            w = pathExists(i+1,j,n,m)
    if w==True:
        dp[i][j]=True
        return True

    dp[i][j]=False
    return False



t = int(input())
for test in range(t):
    n,m = [int(x) for x in input().split()]
    mat,g_c = [],0
    mat.append(['#' for i in range(m+2)])
    for i in range(n):
        x = ["#"]+list(input())+['#']
        mat.append(x)
    mat.append(['#' for i in range(m+2)])
    flag = 0
    for i in range(1,n+1):
        for j in range(1,m+1):
            
            if mat[i][j]=='G':
                g_c+=1

            elif mat[i][j]=='B':


                mat[i][j]='#'

                if mat[i][j-1]=='G':
                    flag=1
                elif mat[i][j-1]!='B': 
                    mat[i][j-1]='#'

                if mat[i][j+1]=='G':
                    flag=1
                elif mat[i][j+1]!='B':
                    mat[i][j+1]='#'

                if mat[i+1][j]=='G':
                    flag=1
                elif mat[i+1][j]!='B': 
                    mat[i+1][j]='#'

                if mat[i-1][j]=='G':
                    flag=1
                elif mat[i-1][j]!='B':
                    mat[i-1][j]='#'
    if flag==1:
        print("NO")
        continue
    if g_c==0:
        print("YES")
        continue
    #pathexists from all G
    flag=0
    dp = []
    dp.append([False for i in range(m+2)])
    for i in range(n):
        x = [False]+[None for i in range(m)]+[False]
        dp.append(x)
    dp.append([False for i in range(m+2)])
    for i in range(1,n+1):
        for j in range(1,m+1):
            if mat[i][j]=='#':
                dp[i][j]=False
   # print(dp)
    for i in range(1,n+1):
        for j in range(1,m+1):
            if mat[i][j]=='G':
                visited=set()
                x = pathExists(i,j,n,m)
                if x==False:
                    flag=1
    if flag==1:
        print("NO")
    else:
        print("YES")


                

    
