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.math.*;
import java.util.*;
import javafx.util.Pair;

public class Level {

    public static Container.Reader in = new Container.Reader();
    public static Container.Print out = new Container.Print();
    public static char[][] z = null;
    public static boolean[][] v = null;
    public static int n = 0, m = 0;

    public static int dfs(int r, int c) {
        v[r][c] = true;
        int sum = 0;
        if (r > 0) {
            if (!v[r - 1][c]) {
                if (z[r - 1][c] == '.') {
                    sum += dfs(r - 1, c);
                } else if (z[r - 1][c] == 'G') {
                    sum++;
                    sum += dfs(r - 1, c);
                }
            }

        }
        if (r < n - 1) {
            if (!v[r + 1][c]) {
                if (z[r + 1][c] == '.') {
                    sum += dfs(r + 1, c);
                } else if (z[r + 1][c] == 'G') {
                    sum++;
                    sum += dfs(r + 1, c);
                }
            }
        }
        if (c > 0) {
            //c-1
            if (!v[r][c - 1]) {
                if (z[r][c - 1] == '.') {
                    sum += dfs(r, c - 1);
                } else if (z[r][c - 1] == 'G') {
                    sum++;
                    sum += dfs(r, c - 1);
                }
            }
        }
        if (c < m - 1) {
            if (!v[r][c + 1]) {
                if (z[r][c + 1] == '.') {
                    sum += dfs(r, c + 1);
                } else if (z[r][c + 1] == 'G') {
                    sum++;
                    sum += dfs(r, c + 1);
                }
            }
        }
        return sum;
    }

    public static int dfs2(int r, int c) {
        v[r][c] = true;
        int sum = 0;
        if (r > 0) {
            if (!v[r - 1][c]) {
                if (z[r - 1][c] == '.' || z[r - 1][c] == 'G') {
                    sum += dfs2(r - 1, c);
                } else if (z[r - 1][c] == 'B') {

                    sum += dfs2(r - 1, c) + 1;
                }
            }

        }
        if (r < n - 1) {
           
            if (!v[r + 1][c]) {
                if (z[r + 1][c] == '.' || z[r + 1][c] == 'G') {
                    sum += dfs2(r + 1, c);
                } else if (z[r + 1][c] == 'B') {

                    sum += dfs2(r + 1, c) + 1;
                }
            }
        }
        if (c > 0) {
            //c-1
            
            if (!v[r][c - 1]) {
              //  System.out.println(r+" "+c);
                if (z[r][c - 1] == '.' || z[r][c - 1] == 'G') {
                  
                    sum += dfs2(r, c - 1);
                } else if (z[r][c - 1] == 'B') {

                    sum += dfs2(r, c - 1) + 1;
                }

            }
        }
        if (c < m - 1) {
            if (!v[r][c + 1]) {
                if (z[r][c + 1] == '.' || z[r][c + 1] == 'G') {
                    sum += dfs2(r, c + 1);
                } else if (z[r][c + 1] == 'B') {
                  
                    sum += dfs2(r, c + 1) + 1;
                }
            }
        }
        return sum;
    }

    public static void block(int r, int c) {
        if (r > 0) {
            if (z[r - 1][c] == '.') {
                z[r - 1][c] = '#';
            }
        }
        if (r < n - 1) {
            if (z[r + 1][c] == '.') {
                z[r + 1][c] = '#';
            }
        }
        if (c > 0) {
            if (z[r][c - 1] == '.') {
                z[r][c - 1] = '#';
            }
        }
        if (c < m - 1) {
            if (z[r][c + 1] == '.') {
                z[r][c + 1] = '#';
            }
        }

    }

    public static void main(String[] args) throws IOException {
        int T = in.nextInt();
        while (T-- > 0) {
            n = in.nextInt();
            m = in.nextInt();
            z = new char[n][m];
            v = new boolean[n][m];
            int g = 0;
            for (int i = 0; i < n; i++) {
                String line = in.next();
                for (int j = 0; j < line.length(); j++) {
                    z[i][j] = line.charAt(j);
                    if (z[i][j] == 'G') {
                        g++;
                    }
                }
            }
            //block the Bs
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (z[i][j] == 'B') {
                        block(i, j);
                    }
                }
            }
            
            // System.out.println(z[n - 1][m - 1]);
            //dfs from the tail
             if (z[n - 1][m - 1] == '.') {
                int count = dfs(n - 1, m - 1);
                v = new boolean[n][m];
                int count2 = dfs2(n - 1, m - 1);
                if (count == g && count2 == 0) {
                    System.out.println("Yes");
                } else {
                    System.out.println("No");
                }
            } else {
                if (g == 0) {
                    System.out.println("Yes");
                } else {
                    System.out.println("No");
                }
            }

        }

    }

    public static class Algo {

        public static long pow(long a, long b) {
            long res = 1;
            while (b > 0) {
                if (b % 2 != 0) {
                    res *= a;
                }
                b /= 2;
                a *= a;
            }
            return res;
        }

        public static int lowerBound(ArrayList<Long> list, int length, long value) {
            int low = 0;
            int high = length;
            while (low < high) {
                final int mid = (low + high) / 2;
                if (value <= list.get(mid)) {
                    high = mid;
                } else {
                    low = mid + 1;
                }
            }
            return low;
        }

        public static int upperBound(ArrayList<Long> list, int length, long value) {
            int low = 0;
            int high = length;
            while (low < high) {
                final int mid = (low + high) / 2;
                if (value >= list.get(mid)) {
                    low = mid + 1;
                } else {
                    high = mid;
                }
            }
            return low;
        }

        public static void merge(int arr[], int l, int m, int r) {
            int n1 = m - l + 1;
            int n2 = r - m;

            int L[] = new int[n1];
            int R[] = new int[n2];

            for (int i = 0; i < n1; ++i) {
                L[i] = arr[l + i];
            }
            for (int j = 0; j < n2; ++j) {
                R[j] = arr[m + 1 + j];
            }

            int i = 0, j = 0;

            int k = l;
            while (i < n1 && j < n2) {
                if (L[i] <= R[j]) {
                    arr[k] = L[i];
                    i++;
                } else {
                    arr[k] = R[j];
                    j++;
                }
                k++;
            }

            while (i < n1) {
                arr[k] = L[i];
                i++;
                k++;
            }

            while (j < n2) {
                arr[k] = R[j];
                j++;
                k++;
            }
        }

        public static void sort(int arr[], int l, int r) {
            if (l < r) {
                int m = (l + r) / 2;

                sort(arr, l, m);
                sort(arr, m + 1, r);

                merge(arr, l, m, r);
            }
        }

        public static ArrayList<Integer> sieve(int n) {
            long sqr = (long) Math.sqrt(n);
            boolean[] isPrime = new boolean[n + 1];
            for (int i = 0; i <= n; i++) {
                isPrime[i] = true;
            }
            for (int i = 2; i <= sqr; i++) {
                if (isPrime[i]) {
                    for (int p = i * i; p <= n; p += i) {
                        isPrime[p] = false;
                    }
                }
            }
            ArrayList<Integer> list = new ArrayList<Integer>();
            for (int i = 0; i <= n; i++) {
                if (isPrime[i]) {
                    list.add(i);
                }
            }
            list.remove(0);
            list.remove(0);
            return list;
        }

        public static boolean isPrime(long n) {
            boolean res = true;
            List l = sieve((int) Math.sqrt(n));
            for (int i = 0; i < l.size(); i++) {
                int curPrime = (int) l.get(i);
                if (n % curPrime == 0) {
                    res = false;
                    break;
                }
            }
            return res;
        }

        public static ArrayList factorizatin(int n) {

            ArrayList<Integer> list = new ArrayList<Integer>();
            if (n == 1) {
                list.add(1);
                return list;
            } else if (n == 2) {
                list.add(2);
                return list;
            } else {
                if (isPrime(n)) {
                    System.out.println(-1);
                    return null;
                } else {
                    Iterator ptr = sieve((int) Math.sqrt(n)).iterator();
                    if (ptr.hasNext()) {
                        int cur = (int) ptr.next();
                        // System.out.println(cur);
                        while (n != 1) {
                            System.out.println(n);
                            while (n % cur == 0) {
                                list.add(cur);
                                n /= cur;
                            }
                            if (ptr.hasNext()) {
                                cur = (int) ptr.next();
                            }
                            //System.out.println(cur);
                        }
                    }
                    if (n > 2) {
                        list.add(n);
                    }
                }
                return list;
            }
        }

        public static long gcd(long a, long b) {
            if (b == 0) {
                return a;
            } else {
                return gcd(b, a % b);
            }
        }

        public static long lcm(long a, long b) {
            long ab = a * b;
            long gcd = gcd(a, b);
            return ab / gcd;
        }

        public static int bs(int[] z, int k) {
            int res = 0;
            int l = 0;
            int r = z.length - 1;
            int mid = (l + r) / 2;
            while (l <= r) {

                if (z[mid] == k) {
                    res = 1;
                    break;
                }
                if (z[mid] > k) {
                    r = mid - 1;
                } else {
                    l = mid + 1;
                }
                mid = (l + r) / 2;
            }
            return res;
        }

        public static void solve() {
            int n = Integer.parseInt(in.next());
            int target = Integer.parseInt(in.next());
            int[] z = new int[n];
            for (int i = 0; i < n; i++) {
                z[i] = Integer.parseInt(in.next());
            }
            Arrays.sort(z);
            int ptr1 = 0;
            int ptr2 = n - 1;
            int wind = z[ptr1] + z[ptr2];
            if (wind == target) {
                System.out.println(ptr1 + "-" + ptr2);
            } else {
                while (ptr1 < ptr2 && wind != target) {
                    if (wind > target) {
                        wind -= z[ptr2--];
                        wind += z[ptr2];
                    } else {
                        wind -= z[ptr1++];
                        wind += z[ptr1];
                    }
                }
                if ((ptr1 != 0 || ptr2 != n - 1) && ptr2 != ptr1) {
                    System.out.println(ptr1 + "-" + ptr2);
                } else {
                    System.out.println(-1);
                }
            }
        }

        public static void sliding() {
            int n = Integer.parseInt(in.next());
            int k = Integer.parseInt(in.next());
            int[] z = new int[n];
            for (int i = 0; i < n; i++) {
                z[i] = Integer.parseInt(in.next());
            }
            int wind = 0;
            for (int i = 0; i < k; i++) {
                wind += z[i];
            }
            int max = wind;
            for (int i = k; i < n; i++) {
                wind += z[i];
                wind -= z[i - k];
                max = Math.max(max, wind);
            }
            System.out.println(max);
        }

        public static ArrayList<Long> dd(long n) {
            ArrayList<Long> list = new ArrayList<Long>();
            for (long i = 1; i * i <= n; i++) {
                if (n % i == 0) {
                    list.add(n / i);
                    list.add(i);
                }
            }

            return list;
        }
    }

    private static class Container {

        public static class Print {

            private final BufferedWriter bw;

            public Print() {
                this.bw = new BufferedWriter(new OutputStreamWriter(System.out));
            }

            public void print(Object object) throws IOException {
                bw.append(object + "");
            }

            public void println(Object object) throws IOException {
                print(object);
                bw.append("\n");
            }

            public void close() throws IOException {
                bw.close();
            }
        }

        private static class Reader {

            BufferedReader br;
            StringTokenizer st;

            public Reader() {
                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;
            }

            BigInteger nextBigInteger() {
                return new BigInteger(next());
            }

        }
    }
}