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

public class Main {
	static boolean valid(int x,int y,int n,int m) {
		if(x>-1 && x<n && y>-1 && y<m) {
			return true;
		}
		return false;
	}
	static boolean check(char[][] graph,int i,int j,int n,int m,boolean[][] visited) {
		visited[i][j]=true;
//		System.out.println(i+" "+j);
		if(i==n-1 && j==m-1) {
			visited[i][j]=false;
			return true;
		}
		else {
			boolean left=false;
			boolean right=false;
			boolean up=false;
			boolean down=false;
			if(valid(i+1,j,n,m) && (graph[i+1][j]=='.' ||graph[i+1][j]=='G') && !visited[i+1][j] ) {
				left=check(graph,i+1,j,n,m,visited);
				if(left) {
					return true;
				}
				if(left && graph[i+1][j]=='G') {
					graph[i+1][j]='.';
				}
			}
			if(valid(i-1,j,n,m) && (graph[i-1][j]=='.' ||graph[i-1][j]=='G') && !visited[i-1][j]) {
				right=check(graph,i-1,j,n,m,visited);
				if(right && graph[i-1][j]=='G') {
					graph[i-1][j]='.';
				}
				if(right) {
					return true;
				}
			}if(valid(i,j+1,n,m) && (graph[i][j+1]=='.' ||graph[i][j+1]=='G') && !visited[i][j+1]) {
				up=check(graph,i,j+1,n,m,visited);
				if(up && graph[i][j+1]=='G') {
					graph[i][j+1]='.';
				}
				if(up) {
					return true;
				}
			}if(valid(i,j-1,n,m) && (graph[i][j-1]=='.' ||graph[i][j-1]=='G') && !visited[i][j-1]) {
				down=check(graph,i,j-1,n,m,visited);
				if(down && graph[i][j-1]=='G') {
					graph[i][j-1]='.';
				}
				
			}
			visited[i][j]=false;
			return left|right|up|down;
		}
		
	}
	public static void main(String[] args) throws IOException 
	{ 
		FastScanner f = new FastScanner(); 
		int t=f.nextInt();
//		int t=1;
		while(t-->0){
			int n=f.nextInt();
			int m=f.nextInt();
			char[][] graph=new char[n][m];
			boolean[][] visited=new boolean[n][m];
			for(int i=0;i<n;i++) {
				char[] a=f.next().toCharArray();
				for(int j=0;j<m;j++) {
					graph[i][j]=a[j];
				}
			}
			boolean flag=true;
			for(int i=0;i<n;i++) {
				for(int j=0;j<m;j++) {
					if(graph[i][j]=='B') {
						if(valid(i+1,j,n,m)) {
							if(graph[i+1][j]=='.' ) {
								graph[i+1][j]='#';
							}
							else if(graph[i+1][j]=='G') {
								flag=false;
								break;
							}
						}
						if(valid(i-1,j,n,m)) {
							if(graph[i-1][j]=='.' ) {
								graph[i-1][j]='#';
							}
							else if(graph[i-1][j]=='G') {
								flag=false;
								break;
							}
						}
						if(valid(i,j+1,n,m)) {
							if(graph[i][j+1]=='.' ) {
								graph[i][j+1]='#';
							}
							else if(graph[i][j+1]=='G') {
								flag=false;
								break;
							}
						}
						if(valid(i,j-1,n,m)) {
							if(graph[i][j-1]=='.' ) {
								graph[i][j-1]='#';
							}
							else if(graph[i][j-1]=='G') {
								flag=false;
								break;
							}
						}
					}
					if(!flag) {
						break;
					}
				}
			}
//			System.out.println(flag);
			if (!flag) {
				System.out.println("NO");
			}
			else {
				
			
			for(int i=0;i<n;i++) {
				for(int j=0;j<m;j++) {
					if(graph[i][j]=='G' && !check(graph,i,j,n,m,visited)) {
//						System.out.println(i+" "+j);
						flag=false;
						break;
					}
				}
			}
			if(flag) {
				System.out.println("YES");
			}
			else {
				System.out.println("NO");
			}
		}}
		
	} 
	static void sort(int [] a) {
        ArrayList<Integer> q = new ArrayList<>();
        for (int i: a) q.add(i);
        Collections.sort(q);
        for (int i = 0; i < a.length; i++) a[i] = q.get(i);
    }
	
	static int gcd(int a, int b)
    {
        if (a == 0)
            return b; 
        return gcd(b % a, a); 
    }
    
    static int lcm(int a, int b)
    {
        return (a / gcd(a, b)) * b;
    }
    
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
		double nextDouble() {
			return Double.parseDouble(next());
		}
		long[] readLongArray(int n) {
			long[] a=new long[n];
			for (int i=0; i<n; i++) a[i]=nextLong();
			return a;
		}
	}
} 