import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int test=sc.nextInt();
		while(test-->0){
		    int n=sc.nextInt();
		    int m=sc.nextInt();
		    int grid[][]=new int[n][m];
		    String s;
		    int gcnt=0;
		    for(int i=0;i<n;i++){
		        s=sc.next();
		        for(int j=0;j<m;j++){
		            if(s.charAt(j)=='#')grid[i][j]=-1;
		            else if(s.charAt(j)=='.')grid[i][j]=0;
		            else if(s.charAt(j)=='G'){grid[i][j]=1;gcnt++;}
		            else grid[i][j]=-2;
		        }
		    }
		    int dx[]={0,0,-1,1};
		    int dy[]={-1,1,0,0};
		    int x,y;
		    for(int i=0;i<n;i++){
		        for(int j=0;j<m;j++){
		            if(grid[i][j]==-2){
		                for(int k=0;k<4;k++){
		                    x=i+dx[k];y=j+dy[k];
		                    if(x<0 || y<0 || x>=n ||y>=m || grid[x][y]==-1 || grid[x][y]==1 || grid[x][y]==-2)continue;
		                    
		                    grid[x][y]=-1;
		                    
		                } 
		            }
		        }
		    }
		    
		    boolean valid=true;
		    Queue<int[]> qu=new LinkedList<>();
		    boolean vis[][]=new boolean[n][m];
		    if(grid[n-1][m-1]!=-1){
    		    vis[n-1][m-1]=true;
    		    qu.add(new int[]{n-1,m-1});
    		    int cur[];
    		    while(!qu.isEmpty()){
    		        cur=qu.poll();
    		        
    		        for(int i=0;i<4;i++){
    		            x=cur[0]+dx[i];y=cur[1]+dy[i];
    		            if(x<0 || y<0 || x>=n || y>=m || grid[x][y]==-1)continue;
    		            
    		            if(grid[x][y]==-2){
    		                valid=false;qu.clear();break;
    		            }
    		            
    		            else if(grid[x][y]==1)gcnt--;
    		            
    		            if(!vis[x][y]){
    		                vis[x][y]=true;
    		                qu.add(new int[]{x,y});
    		            }
    		            
    		        }
    		    }
		    }
		    if(gcnt>0)valid=false;
		    if(valid)
		    System.out.println("Yes");
		    else System.out.println("No");
		}
	}
}
