import java.io.*;
import java.util.*;

public class test {
   static class sort implements Comparator<long[]>
   {
	   	public int compare(long[] a,long[] b)
	   	{
	   		if(a[0]>b[0]) return 1;
	   		if(a[0]<b[0]) return -1;
	   		return 0;
	   	}
   }
   public static void print(Object o)
   {
   	 PrintWriter out = new PrintWriter(System.out);
	out.println(o.toString());
	out.flush();
   }
   public static int intIn(String st)
   {
   	  return Integer.parseInt(st);
   }
   
   
    public static long Dis(int a,int b,int[][] arr)
    {
    	long sum =0l;
    	for(int[] x : arr)
    	{
    		sum = sum + Math.abs(a-x[0]) +Math.abs(b-x[1]) + 0l;
    	}
    	return sum;
    }
    public static void pr(Object o)
    {
    	System.out.println(o.toString());
    }
	public static void main (String[] args) throws Exception {
        
		BufferedReader bf=new BufferedReader(new InputStreamReader(System.in));
        
		int y=Integer.parseInt(bf.readLine());
		int[] map=new int[1000001];
		for(int h=0;h<y;h++)
		{
		    String[] xl=(bf.readLine()).split(" ");//int i=0;
            int a,b,m,n;//long a,b,m,n;
            n=Integer.parseInt(xl[0]);//n=Long.parseInt(xl[0]);
            a=Integer.parseInt(xl[1]);
            char[][] arr = new char[n][a];
            
            for(int o=0;o<n;o++)
            {
            	arr[o] = bf.readLine().toCharArray();
            }
           // for(int o=0;o<n;o++) System.out.println(String.valueOf(rt[o]));
            boolean bol=true;
            int[][] dir={{0,1},{1,0},{-1,0},{0,-1}};int ct=0;
            for(int o=0;o<n;o++)
            {
            	//if(!bol) break;
            	for(int j=0;j<a;j++)
            	{
            		if(arr[o][j]=='B')
            		{
            			int x,yi;
            			x=o;yi=j;
            			for(int[] d : dir)
            			{
            				x = o+d[0];yi=j+d[1];
            				if(x<0 || yi<0 || x>=n || yi>=a) continue;
            				if(arr[x][yi] == 'G' || (  (x==(n-1)) && (yi==(a-1)))  ) 
            				{
            					bol=false;
            				}
            			}
            		}
            		else if(arr[o][j]=='G') ct++;
            	}
            }
            if(bol || (ct==0)) pr("YES");
            else pr("no");
            
            
            
		}
	}
}
/*
1
2 2
2 0
1 2

*/



