import java.util.*;
 
public class SolveTheMaze {
	static boolean bfs(int ri , int ci , char[][] gp)
	{
		Queue<Integer> q = new LinkedList<Integer>();
		q.add(ri);
		q.add(ci);
		int n = gp.length , m = gp[0].length;
		boolean[][] vis = new boolean[n][m];
		while (!q.isEmpty())
		{
			int i = q.remove();
			int j = q.remove();
			if (i==n-1 && j==m-1) return true;
			vis[i][j] = true;
			if (i-1>=0 && gp[i-1][j]=='.' && !vis[i-1][j]) { q.add(i-1); q.add(j); }
			if (i+1<n  && gp[i+1][j]=='.' && !vis[i+1][j]) { q.add(i+1); q.add(j); }
			if (j-1>=0 && gp[i][j-1]=='.' && !vis[i][j-1]) { q.add(i); q.add(j-1); }
			if (j+1<m  && gp[i][j+1]=='.' && !vis[i][j+1]) { q.add(i); q.add(j+1); }
		}
		return false;
	}
	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int t = s.nextInt();
		while (t-->0)
		{
			int n = s.nextInt() , m = s.nextInt();
			char[][] gp = new char[n][];
			for (int i=0;i<n;i++)
				gp[i] = s.next().toCharArray();
			Queue<Integer> q = new LinkedList<Integer>();
			for (int i=n-1;i>=0;i--)
			{
				for (int j=m-1;j>=0;j--)
				{
					if (gp[i][j]=='G') { q.add(i); q.add(j); }
					else if (gp[i][j]=='B') {
						if (i-1>=0 && gp[i-1][j]=='.')gp[i-1][j] = '#';
						if (i+1<n  && gp[i+1][j]=='.')gp[i+1][j] = '#';
						if (j-1>=0 && gp[i][j-1]=='.')gp[i][j-1] = '#';
						if (j+1<m  && gp[i][j+1]=='.')gp[i][j+1] = '#';
					}
				}
			}
			if (gp[n-1][m-1]=='B') {
				if (q.isEmpty())
				System.out.println("YES");
				else
				System.out.println("NO");
				continue;
			}
			boolean pos = true;
			while(!q.isEmpty())
			{
				int cx = q.remove();
				int cy = q.remove();
				if (!bfs(cx , cy, gp))
				{
					pos = false;
					break;
				}
				else {
					gp[cx][cy] = '.';
				}
			}
			if (pos) System.out.println("YES");
			else System.out.println("NO");
		}
	}
 
}
