import java.util.*;
import java.io.*;
public class cf_1365 {
	
	static int n,l,r,m;
	static char[][] ma;
	static StringBuilder answer;
//	static HashMap<Integer,Integer> map=new HashMap<>();
	public static void main(String[] args) throws IOException{
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		Integer t=Integer.parseInt(br.readLine().trim());
		answer=new StringBuilder();
		while(t-->0) {
			StringTokenizer tok=new StringTokenizer(br.readLine()," ");
			n=Integer.parseInt(tok.nextToken());
			m=Integer.parseInt(tok.nextToken());
			ma=new char[n][m];
			int totG=0;
			for(int i=0;i<n;i++) {
				String rr=br.readLine().trim();
				for(int j=0;j<m;j++) {
					ma[i][j]=rr.charAt(j);
					if(ma[i][j]=='G') {
						totG++;
					}
				}
			}vis=new boolean[n][m];
			for(int i=0;i<n;i++) {
				for(int j=0;j<m;j++) {
					if(ma[i][j]=='B') {
						if(i+1<n && ma[i+1][j]=='.') {
							ma[i+1][j]='#';
						}
						if(i-1>=0 && ma[i-1][j]=='.') {
							ma[i-1][j]='#';
						}
						if(j+1<m && ma[i][j+1]=='.') {
							ma[i][j+1]='#';
						}
						if(j-1>=0 && ma[i][j-1]=='.') {
							ma[i][j-1]='#';
						}
						
					}
//					System.out.print(ma[i][j]+" ");
				}
//				System.out.println();
			}
			totb=totg=0;
			tpt(ma);
			if(totb>0) {
				answer.append("NO\n");
			}
			else if(totg==totG) {
				answer.append("YES\n");
			}
			else {
				answer.append("NO\n");
			}
			
			
//				addtoans(ans);
		}
		System.out.print(answer);
		
	}
	static boolean[][] vis;
	static int totg,totb;
	static int[] row= {1,-1,0,0},col={0,0,1,-1};
	static void tpt(char[][] ma) {
		
		Queue<pair> q=new LinkedList<>();
		if(ma[n-1][m-1]!='#')
		q.add(new pair(n-1,m-1));
		int count=0;
		
		while(!q.isEmpty()) {
			pair curr=q.poll();
			
			for(int j=0;j<4;j++) {
				
				int r=curr.i;
				r+=row[j];
				int c=curr.j; 
				c+=col[j];
//				System.out.println(r+" "+c);
				if(r>=0 && r<n && c<m && c>=0 && !vis[r][c] && (ma[r][c]=='.' || ma[r][c]=='B' || ma[r][c]=='G')){
					if(ma[r][c]=='G')totg++;
					if(ma[r][c]=='B')totb++;
					q.add(new pair(r,c));
					vis[r][c]=true;
				}
			}
			
				
		}
		
	}
	static class pair{
		int i,j;
		pair(int u,int v){
			i=u;
			j=v;
		}
	}
	static void addtoans(int a){
		answer.append(a+"\n");
	}	

//	static class ss implements Comparator<pair>{
//		public int compare(pair a,pair b) {
//			if(a.b!=b.b)return a.a-b.a;
//			return 0;
//			
//			
//			
//	}	
	}


