// Working program with FastReader 
import java.io.*;
import java.util.*;

public class ProblemB3 
{
    static PrintWriter out;
    static FastReader sc;
    static class FastReader 
    { 
        BufferedReader br; 
        StringTokenizer st; 
        public FastReader(){ 
            br = new BufferedReader(new InputStreamReader(System.in)); 
        } 
        String next(){ 
            while (st == null || !st.hasMoreElements()){ 
                try{ 
                    st = new StringTokenizer(br.readLine()); 
                } 
                catch (IOException e){ 
                    e.printStackTrace(); 
                } 
            } 
            return st.nextToken(); 
        } 
        int nextInt(){ 
            return Integer.parseInt(next()); 
        } 
        long nextLong(){ 
            return Long.parseLong(next()); 
        } 
        double nextDouble(){ 
            return Double.parseDouble(next()); 
        }
        String nextLine(){ 
            String str = ""; 
            try{ 
                str = br.readLine(); 
            } 
            catch(IOException e){ 
                e.printStackTrace(); 
            }
            return str; 
        }
    }
    static int diffX[] = {-1,0,0,1};
    static int diffY[] = {0,-1,1,0};
    public static void DFS(int x,int y,char graph[][],boolean visited[][]){
        visited[x][y] = true;
        int n = graph.length;
        int m = graph[0].length;
        //Traverse nbrs
        for(int i = 0; i < 4;i++){
            int X = x + diffX[i];
            int Y = y + diffY[i];
            if(X >= 0 && Y >= 0 && X < n && Y < m){
                if(graph[X][Y] == 'B'){
                    graph[x][y] = '#';
                    return; 
                }    
                else if(!visited[X][Y] && (graph[X][Y] == '.' || graph[X][Y] == 'G')){
                    DFS(X,Y,graph,visited);
                }
            }
        }
    }
    public static int countGood(int x,int y,char graph[][],boolean visited[][]){
        visited[x][y] = true;
        int n = graph.length;
        int m = graph[0].length;
        int goodCount = 0;
        
        if(graph[x][y] == 'G')
            goodCount++;
        
        //Traverse nbrs
        for(int i = 0; i < 4;i++){
            int X = x + diffX[i];
            int Y = y + diffY[i];
            if(X >= 0 && Y >= 0 && X < n && Y < m){    
                if(!visited[X][Y] && (graph[X][Y] == '.' || graph[X][Y] == 'G')){
                    goodCount += countGood(X,Y,graph,visited);
                }
            }
        }
        return goodCount;
    }
    public static void runTest(){
        int n = sc.nextInt();
        int m = sc.nextInt();
        int goodCount = 0;
        char graph[][] = new char[n][m];
        for(int i = 0; i < n;i++){
            String s = sc.next();
            for(int j = 0; j < m;j++){
                graph[i][j] = s.charAt(j);
                if(s.charAt(j) == 'G')
                    goodCount++;
            }
        }
        
        boolean visited[][] = new boolean[n][m];
        DFS(n-1,m-1,graph,visited);
        
        if(graph[n-1][m-1] == '#'){
            if(goodCount == 0)
                out.println("YES");
            else
                out.println("NO");
            return;
        }
        
        for(int i = 0; i < n;i++){
            for(int j = 0; j < m;j++){
                visited[i][j] = false;
            }
        }
        int gc = countGood(n-1,m-1,graph,visited);
//        for(int i = 0; i < n;i++){
//            for(int j = 0; j < m;j++){
//                out.print(graph[i][j] + " ");
//            }
//            out.println();
//        }
        //out.println(goodCount + " , " + gc);
        if(gc == goodCount)
            out.println("YES");
        else
            out.println("NO");
    }
    public static void main(String args[]){
        sc = new FastReader();
        out = new PrintWriter(System.out);
        int t = sc.nextInt();
        while(t > 0){
            runTest();
            out.flush();
            t--;
        }
    }
} 
