
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Round648 {

	static int X[]= {-1,0,0,1};
	static int Y[]= {0,-1,1,0};
	static class Reader {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;

		public Reader() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public Reader(String file_name) throws IOException {
			din = new DataInputStream(new FileInputStream(file_name));
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}

		public String readLine() throws IOException {
			byte[] buf = new byte[64]; // line length
			int cnt = 0, c;
			while ((c = read()) != -1) {
				if (c == '\n')
					break;
				buf[cnt++] = (byte) c;
			}
			return new String(buf, 0, cnt);
		}

		public int nextInt() throws IOException {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}

		public long nextLong() throws IOException {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}

		public double nextDouble() throws IOException {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();

			do {
				ret = ret * 10 + c - '0';
			} while ((c = read()) >= '0' && c <= '9');

			if (c == '.') {
				while ((c = read()) >= '0' && c <= '9') {
					ret += (c - '0') / (div *= 10);
				}
			}

			if (neg)
				return -ret;
			return ret;
		}

		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}

		private byte read() throws IOException {
			if (bufferPointer == bytesRead)
				fillBuffer();
			return buffer[bufferPointer++];
		}

		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}
	
	static class Node{
		int val;
		int type;
		int ind;
		
		public Node(int val, int type, int ind) {
			this.val=val;
			this.type=type;
			this.ind=ind;
		}
	}

	public static long[] initArray(int n, Reader scan) throws IOException {

		long arr[] = new long[n];
		for (int i = 0; i < n; i++) {
			arr[i] = scan.nextLong();
		}

		return arr;
	}

	public static long sum(long arr[]) {

		long sum = 0;
		for (long i : arr) {
			sum += (long) i;
		}

		return sum;
	}

	public static long max(long arr[]) {

		long max = Long.MIN_VALUE;

		for (long i : arr) {
			max = Math.max(i, max);
		}

		return max;
	}

	public static long min(long arr[]) {
		long min = Long.MAX_VALUE;

		for (long i : arr) {
			min = Math.min(i, min);
		}

		return min;
	}
	
	public static List<Integer>[] initAdjacency(int n, int e, Reader scan, boolean type) throws IOException{
		
		List<Integer> adj[]=new ArrayList[n+1];
		
		
		for(int i=0;i<e;i++) {
			int u=scan.nextInt();
			int v=scan.nextInt();
			
			if(adj[u]==null) adj[u]=new ArrayList<>();
			if(type&&adj[v]==null) adj[v]=new ArrayList<>();
			
			adj[u].add(v);
			
			if(type) adj[v].add(u);
			
		}
		
		return adj;
	}
	
	public static void main(String[] args) throws IOException {
		
		Scanner scan=new Scanner(System.in);
		int t=scan.nextInt();
		while(t-->0) {
			int n=scan.nextInt();
			int m=scan.nextInt();
			
			int arr[][]=new int[n][m];
			
			for(int i=0;i<n;i++) {
				String s=scan.next();
				for(int j=0;j<m;j++) {
					if(s.charAt(j)=='.') {
						arr[i][j]=0;
					}
					if(s.charAt(j)=='#') {
						arr[i][j]=1;
					}
					
					if(s.charAt(j)=='G') {
						arr[i][j]=2;
					}
					if(s.charAt(j)=='B') {
						arr[i][j]=3;
					}
				}
			}
			
			D(arr, n, m);
		}
		
	}
	
	public static void A(int n, int m ,long arr[][]) {
		
		int rC=0;
		int cC=0;
		
		int rows[]=new int[n];
		int cols[]=new int[m];
		
		
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				if(arr[i][j]==1) {
					rows[i]++;
					cols[j]++;
				}
			}
		}
		
		
		for(int i: rows) {
			if(i==0) {
				rC++;
			}
		}
		
		for(int j: cols) {
			if(j==0) {
				cC++;
			}
		}
		
		int turn=0;
		
		turn= Math.min(rC, cC)%2;
		
		if(turn==0) {
			System.out.println("Vivek");
		}else {
			System.out.println("Ashish");
		}
		
	}
	
	public static void B(List<Node> arr) {
		
		
		boolean allSame=true;
		boolean isInc=true;
		
		int last=0;
		int lastType= arr.get(0).type;
		for(int i=0;i<arr.size();i++) {
			if(arr.get(i).type!=lastType) {
				System.out.println("Yes");
				return;
			}
			
			if(arr.get(i).val<last) {
				isInc=false;
			}
			
			last= arr.get(i).val;
		}
		
		if(isInc) {
			System.out.println("Yes");
		}
		
		else {
			System.out.println("No");
		}
		
		
	}
	
	public static int C(long arr1[], long arr2[], int n) {
		
		int ind[]=new int[n+1];
		
		for(int i=0;i<n;i++) {
			ind[(int)arr2[i]]=i;
		}
		
		int dist[]=new int[n];
		
		for(int i=0;i<n;i++) {
			
			long val=arr1[i];
			int idx= ind[(int)val];
			if(idx<i) {
				dist[i]= i-idx;
			}else {
				dist[i]= n-idx+i;
			}
		}
		
		int maxVals[]=new int[n+1];
		for(int i: dist) {
			maxVals[i]++;
		}
		
		int ans=1;
		
		for(int i: maxVals) {
			ans=Math.max(i, ans);
		}
		
		return ans;
		
		
	}
	
	public static void D(int arr[][], int n, int m) {
		
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				if(arr[i][j]==3) {
					
					for(int k=0;k<4;k++) {
						int x=i+X[k];
						int y=j+Y[k];
						
						if(x>=0&&x<n&&y>=0&&y<m) {
							if(arr[x][y]==2) {
								System.out.println("No");
								return;
							}else if(arr[x][y]==0) {
								arr[x][y]=1;
								
							}
						}
					}
				}
			}
		}
		
		boolean visited[][]=new boolean[n][m];
		
		for(int i=0;i<n;i++) {
			for(int j=0;j<m;j++) {
				if(arr[i][j]==2) {
					boolean ans= dfs(i, j, visited, arr, n, m);
					if(!ans) {
						System.out.println("No");
						return;
					}
				}
			}
		}
		
		System.out.println("Yes");
		
		
		
	}
	
	public static boolean dfs(int i, int j, boolean visited[][], int arr[][], int n, int m) {
		
		if(i==n-1&&j==m-1) {
			
			if(arr[i][j]==1) {
				return false;
			}
			return true;
		}
		
		visited[i][j]=true;
		
		boolean ans=false;
		
		for(int k=0;k<4;k++) {
			int x=i+X[k];
			int y=j+Y[k];
			
			if(x>=0&&x<n&&y>=0&&y<m&&arr[x][y]!=1&&!visited[x][y]) {
				ans= ans|| dfs(x, y, visited, arr, n, m);
			}
		}
		
		return ans;
	}
}


