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 javafx.util.Pair;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;


public class tt_1365D {
    static Scanner sc;
    static FastReader fr;
    public static void main(String[] args){
        sc = new Scanner(System.in);
        fr = new FastReader();
        int test = fr.nextInt();
        for(int t=0; t<test; t++){

            int n = fr.nextInt();
            int m = fr.nextInt();
            int[][] mat = new int[n][m];
            HashSet<Pair<Integer, Integer>> badPeople = new HashSet<>(2500);
            int count = 0;
            for(int i=0; i<n; i++){
                char[] arr = getCharArray();
                for(int j=0; j<m; j++){
                    switch (arr[j]){
                        case 'G':
                            mat[i][j] = 1;
                            count++;
                            break;
                        case 'B':
                            badPeople.add(new Pair<>(i,j));
                            mat[i][j] = 2;
                            break;
                        case '.':
                            mat[i][j] = 3;
                            break;
                        case '#':
                            mat[i][j] = 4;
                            break;
                    }
                }
            }
            // All bad people are captured now
            for(Pair<Integer, Integer> badPerson : badPeople){
                // surround them by wall
                int x = badPerson.getKey();
                int y = badPerson.getValue();
                if(x-1>-1){
                    mat[x-1][y] = 4;
                }
                if(x+1<n){
                    mat[x+1][y]=4;
                }
                if(y-1>-1){
                    mat[x][y-1]=4;
                }
                if(y+1<m){
                    mat[x][y+1]=4;
                }
            }
            // see if all good people are reachable from n-1,m-1 !
            HashSet<Pair<Integer,Integer>> visitedNodes = new HashSet<>(2500);
            int countGoodReachable = getAllGoodReachable(mat, n-1, m-1, visitedNodes, n , m);
            if(count==countGoodReachable){
                System.out.println("Yes");
            }
            else {
                System.out.println("No");
            }
        }
    }

    private static int getAllGoodReachable(int[][] mat, int x, int y, HashSet<Pair<Integer, Integer>> visitedNodes, int n, int m) {
        // if curr is visited it means we have trvelled from it and all reachable points from it.
        int res = 0;
        if(visitedNodes.contains(new Pair<>(x,y))){
            return res;
        }

        visitedNodes.add(new Pair<>(x,y));
        if(mat[x][y]==4){
            return res;
        }
        if(mat[x][y]==1){
            res++;
        }
        if(x-1>-1 && mat[x-1][y] != 4){
            res+=getAllGoodReachable(mat, x-1, y, visitedNodes, n, m);
        }
        if(x+1<n && mat[x+1][y] != 4){
            res+=getAllGoodReachable(mat, x+1, y, visitedNodes, n, m);
        }
        if(y-1>-1 && mat[x][y-1] != 4){
            res+=getAllGoodReachable(mat, x, y-1, visitedNodes, n ,m);
        }
        if(y+1<m && mat[x][y+1] != 4){
            res+=getAllGoodReachable(mat, x, y+1, visitedNodes, n ,m);
        }
        return res;
    }

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt()
        {
            return Integer.parseInt(next());
        }

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static Integer[] getIntArrayFromSingleLine(){
        List<Integer> list = new LinkedList<>();
        String[] str = fr.nextLine().split(" ");
        for(String s: str){
            list.add(Integer.parseInt(s));
        }
        Integer[] arr = new Integer[list.size()];
        return list.toArray(arr);
    }

    public static Long[] getLongArrayFromSingleLine(){
        List<Long> list = new LinkedList<>();
        String[] str = fr.nextLine().split(" ");
        for(String s: str){
            list.add(Long.parseLong(s));
        }
        Long[] longs = new Long[list.size()];
        return list.toArray(longs);
    }

    public static Double[] getDoubleArrayFromSingleLine(){
        List<Double> list = new LinkedList<>();
        String[] str= fr.nextLine().split(" ");
        for(String s: str){
            list.add(Double.parseDouble(s));
        }
        Double[] doubles = new Double[list.size()];
        return list.toArray(doubles);
    }

    public static int[] getArray(int n){
        int[] arr = new int[n];
        for(int i=0; i<n; i++){
            arr[i] = fr.nextInt();
        }
        return arr;
    }

    public static long[] getLongArray(int n){
        long[] res = new long[n];
        for(int i=0; i<n; i++){
            res[i] = fr.nextLong();
        }
        return res;
    }

    public static double[] getDoubleArray(int n){
        double[] arr = new double[n];
        for(int i=0; i<n ; i++){
            arr[i] = fr.nextDouble();
        }
        return arr;
    }

    public static char[] getCharArray(){
        return fr.next().toCharArray();
    }

    public static String[] getStringArray(int n){
        String[] strings = new String[n];
        for(int i=0; i<n; i++){
            strings[i] = fr.next();
        }
        return strings;
    }

    // Get GCD
    public static int getGCD(int a, int b){
        return (a==0 ? b : getGCD(b%a, a));
    }

    public static int getGCD(int[] arr){
        int n = arr.length;
        if(n==0){
            return -1;
        }
        int res = arr[0];
        for(int i=1; i<n; i++){
            res = getGCD(res, arr[i]);
        }
        return res;
    }

    // Get all prime numbers till N using seive of Eratosthenes
    public static List<Integer> getPrimesTill(int n){
        boolean[] arr = new boolean[n+1];
        List<Integer> primes = new LinkedList<>();
        for(int i=2; i<=n; i++){
            if(!arr[i]){
                primes.add(i);
                for(int j=(i*i); j<=n; j+=i){
                    arr[j] = true;
                }
            }
        }
        return primes;
    }


    // This method returns list of PrimeFactors of a number in O(sqrt(N));
    public static Map<Integer,Integer> getPrimeFactors(long n){
        Map<Integer,Integer> res = new HashMap<>();
        int sqrt = (int) Math.sqrt(n);
        if(n%2 == 0){
            int c = 0;
            while(n%2==0){
                c++;
                n/=2;
            }
            res.put(2,c);
        }
        for(int i=3; i<=sqrt; i+=2){
            if(n%i == 0) {
                int c = 0;
                while (n % i == 0) {
                    c++;
                    n /= i;
                }
                res.put(i,c);
            }
        }
        if(n!=1){
            res.put((int)n,1);
        }
        return res;
    }

}