Problem: Vivek has encountered a problem. He has a maze that can be represented as an n × m grid. Each of the grid cells may represent the following:

  * Empty — '.' 
  * Wall — '#' 
  * Good person — 'G' 
  * Bad person — 'B' 



The only escape from the maze is at cell (n, m).

A person can move to a cell only if it shares a side with their current cell and does not contain a wall. Vivek wants to block some of the empty cells by replacing them with walls in such a way, that all the good people are able to escape, while none of the bad people are able to. A cell that initially contains 'G' or 'B' cannot be blocked and can be travelled through.

Help him determine if there exists a way to replace some (zero or more) empty cells with walls to satisfy the above conditions.

It is guaranteed that the cell (n,m) is empty. Vivek can also block this cell.

Input

The first line contains one integer t (1 ≤ t ≤ 100) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers n, m (1 ≤ n, m ≤ 50) — the number of rows and columns in the maze.

Each of the next n lines contain m characters. They describe the layout of the maze. If a character on a line equals '.', the corresponding cell is empty. If it equals '#', the cell has a wall. 'G' corresponds to a good person and 'B' corresponds to a bad person.

Output

For each test case, print "Yes" if there exists a way to replace some empty cells with walls to satisfy the given conditions. Otherwise print "No"

You may print every letter in any case (upper or lower).

Example

Input


6
1 1
.
1 2
G.
2 2
#B
G.
2 3
G.#
B#.
3 3
#B.
#..
GG.
2 2
#B
B.


Output


Yes
Yes
No
No
Yes
Yes

Note

For the first and second test cases, all conditions are already satisfied.

For the third test case, there is only one empty cell (2,2), and if it is replaced with a wall then the good person at (1,2) will not be able to escape.

For the fourth test case, the good person at (1,1) cannot escape.

For the fifth test case, Vivek can block the cells (2,3) and (2,2).

For the last test case, Vivek can block the destination cell (2, 2).

Solution (in JAVA):

Solution:
import java.io.*; 
import java.util.*; 
//import javafx.util.*; 
import java.math.*;
//import java.lang.*;
public class Main 
{ 
    
   // static int n;
//  static HashSet<Integer> adj[];

   // static int dist[];
   // static int remove[];
//    static boolean isLeaf[];
  //   static Long dp[][];
   // static int arr[];
  //  static boolean ok;
    // static long arr[];
    // static long sum[];
  //  static boolean ok;
    static long mod=1000000007;
    static final long oo=(long)1e18;
    public static void main(String[] args) throws IOException { 
    //    Scanner sc=new Scanner(System.in);
        PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
        br = new BufferedReader(new InputStreamReader(System.in));
        int test=nextInt();
       // int test=1;
        
        outer: while(test--!=0){
            int n=nextInt();
            int m=nextInt();
            char arr[][]=new char[n][m];int to=0;
            for(int i=0;i<n;i++){
                String str=next();
                for(int j=0;j<m;j++){
                    arr[i][j]=str.charAt(j);
                    if(arr[i][j]=='G')
                        to++;
                }
            }

            boolean ok=true;
            for(int i=0;i<n;i++){
                for(int j=0;j<m;j++){
                    if(arr[i][j]=='B'){
                        arr[i][j]='#';
                        if(i>0){
                            if(arr[i-1][j]=='G'){
                                ok=false;
                                break;
                            }
                            if(arr[i-1][j]!='B')
                                arr[i-1][j]='#';
                        }
                        if(j>0){
                            if(arr[i][j-1]=='G'){
                                ok=false;
                                break;
                            }
                            if(arr[i][j-1]!='B')
                                arr[i][j-1]='#';
                        }
                        if(i<n-1){
                            if(arr[i+1][j]=='G'){
                                ok=false;
                                break;
                            }
                            if(arr[i+1][j]!='B')
                                arr[i+1][j]='#';
                        }
                        if(j<m-1){
                            if(arr[i][j+1]=='G'){
                                ok=false;
                                break;
                            }
                            if(arr[i][j+1]!='B')
                                arr[i][j+1]='#';
                        }
                    }
                }
            }
            // for(int i=0;i<n;i++){
            //     for(int j=0;j<m;j++){
            //         pw.print(arr[i][j]+" ");
            //     }
            //     pw.println();
            // }
            Queue<Pair> q = new LinkedList<Pair>();
            Pair a=new Pair(n-1,m-1);
            if(arr[n-1][m-1]!='#'){
                q.add(a);    
            }
            int count=0; 
            boolean vis[][]=new boolean[n][m];
            while(!q.isEmpty()){
                Pair p=q.remove();
                
                int i=p.x;int j=p.y;
                
                if(arr[p.x][p.y]=='G'){
                 //   pw.println("ef");
                    count++;
                }
               //pw.println(i+" "+j);
                if(i>0){
                    if(arr[i-1][j]!='#'){
                        Pair np=new Pair(i-1,j);
                        if(!vis[i-1][j]){
                            q.add(np);
                            vis[i-1][j]=true;
                        }
                    }
                    
                }
                if(j>0){
                    if(arr[i][j-1]!='#'){
                        Pair np=new Pair(i,j-1);
                        if(!vis[i][j-1]){
                            q.add(np);
                            vis[i][j-1]=true;
                        }
                    }
                    
                }
                if(i<n-1){
                    if(arr[i+1][j]!='#'){
                        Pair np=new Pair(i+1,j);
                        if(!vis[i+1][j]){
                            q.add(np);
                            vis[i+1][j]=true;
                        }
                    }
                }
                if(j<m-1){
                    if(arr[i][j+1]!='#'){
                        Pair np=new Pair(i,j+1);
                        if(!vis[i][j+1]){
                            q.add(np);
                            vis[i][j+1]=true;
                        }
                    }
                    
                }
                vis[i][j]=true;

            }
            if(ok&&(count==to)){
                pw.println("Yes");
            }
            else{
                pw.println("No");
            }


        }   
        pw.close();
    }
  
    static class Pair implements Comparable<Pair>{
        int x;int y;
        Pair(int x,int y){
          //  this.index=index;
            this.x=x;
            this.y=y;
            //this.z=z;
        }   
        public int compareTo(Pair p){
            return x-p.x;
        }
    }
   static void update(long tree[],int idx,long val){
        
        while(idx<100006){
       
            tree[idx]+=val;
            idx+=(idx)&(-idx);
        }
    }   
    static long sum(long tree[],int idx){
        long sum=0;
        while(idx>0){
           
            sum+=tree[idx];
            idx-=(idx)&(-idx);
        }
        return sum;
    }
    public static BufferedReader br;
    public static StringTokenizer st;
    public static String next() {
        while (st == null || !st.hasMoreTokens()) {
       try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                throw new RuntimeException(e);
            }
        }
        return st.nextToken();
    }
 
    public static Integer nextInt() {
        return Integer.parseInt(next());
    }
    public static Long nextLong() {
        return Long.parseLong(next());
    }
 
    public static Double nextDouble() {
        return Double.parseDouble(next());
    }
    // static class Pair{
    //     int x;int y;
    //     Pair(int x,int y,int z){
    //         this.x=x;
    //         this.y=y;
    //        // this.z=z;
    //      //   this.z=z;
    //       //  this.i=i;
    //     }
    // }
    // static class sorting implements Comparator<Pair>{
    //     public int compare(Pair a,Pair b){
    //         //return (a.y)-(b.y);
    //         if(a.y==b.y){
    //             return -1*(a.z-b.z);
    //         }
    //         return (a.y-b.y);
    //     }
   // }

    static long ncr(long n,long r){
        
        if(r==0)
            return 1l;
        long val=ncr(n-1,r-1);
        val=(n*val);
        val=(val/r);
        return val;
    }

    public static int[] na(int n)throws IOException{
        int[] a = new int[n];
        for(int i = 0;i < n;i++)a[i] = nextInt();
        return a;
    }
    static class query implements Comparable<query>{
        int l,r,idx,block;
        static int len;
        query(int l,int r,int i){
            this.l=l;
            this.r=r;
            this.idx=i;
            this.block=l/len;
        }   
        public int compareTo(query a){
            return block==a.block?r-a.r:block-a.block;
        }
    }
    
    // static class sorting implements Comparator<Pair>{  
    //     public int compare(Pair a1,Pair a2){  
    //         if(o1.a==o2.a)
    //             return (o1.b>o2.b)?1:-1;  
    //         else if(o1.a>o2.a)  
    //             return 1;  
    //         else  
    //             return -1;  
    //     }
    // }  
    static boolean isPrime(int n) { 
        if (n <= 1) 
            return false; 
        if (n <= 3) 
            return true; 
        if (n % 2 == 0 ||  
            n % 3 == 0) 
            return false; 
      
        for (int i = 5; 
                 i * i <= n; i = i + 6) 
            if (n % i == 0 || 
                n % (i + 2) == 0) 
                return false; 
      
        return true; 
    } 
    static long gcd(long a, long b) { 
      if (b == 0) 
        return a; 
      return gcd(b, a % b);  
    }  
    // To compute x^y under modulo m 
    static long power(long x, long y, long m){ 
        if (y == 0) 
            return 1;      
        long p = power(x, y / 2, m) % m; 
        p = (p * p) % m; 
      
        if (y % 2 == 0) 
            return p; 
        else
            return (x * p) % m; 
    }
    static long fast_pow(long base,long n,long M){
        if(n==0)
           return 1;
        if(n==1)
        return base;
        long halfn=fast_pow(base,n/2,M);
        if(n%2==0)
            return ( halfn * halfn ) % M;
        else
            return ( ( ( halfn * halfn ) % M ) * base ) % M;
    }
       static long modInverse(long n,long M){
        return fast_pow(n,M-2,M);
    }
    // (1,1)   

    //     (3,2)   (3,5)

}