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:
//package Round648;

import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;

/**
 * @author sguar <shugangcao@gmail.com>
 * strive for greatness
 * Created on 2020-01-10
 */
public class D {
    InputStream is;
    PrintWriter out;


    private static final String INPUT_FILE_NAME = "/Users/sguar/IdeaProjects/kotlinLearn/src/input.txt";
    char [][] maze;
    boolean [][] vis;
    int n;
    int m;

    int [] nx = {-1, 0, 0, 1};
    int [] ny = {0, -1, 1, 0};

    void solve() {
        int t = ni();

        while (t -- > 0) {
            n = ni();
            m = ni();
            debug(n, m);
            maze = nm(n, m);
            debug(maze);
            int good = 0;
            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    if (maze[i][j] == 'G') {
                        good++;
                    }
                }
            }

            vis = new boolean[n][m];

            boolean flag = !block(n - 1, m - 1);


            debug(maze);
            debug(flag);
            if (flag) {

                debug(good);
                init();
                debug(find(n - 1, m - 1));
                init();
                flag = find(n - 1, m - 1) == good;
            }

            if (flag) {
                out.println("Yes");
            } else {
                out.println("No");
            }

        }
    }

    private int find(int x, int y) {
        //debug(x, y, maze[x][y]);
        if (vis[x][y] || maze[x][y] == '#') {
            return 0;
        }
        vis[x][y] = true;

        int ans = 0;
        if (maze[x][y] == 'G') {
            ans++;
        }

        for (int i = 0; i < 4; i++) {
            int xi = x + nx[i];
            int yi = y + ny[i];
            if (xi >= 0 && xi < n && yi >= 0 && yi < m && !vis[xi][yi] && maze[xi][yi] != '#') {
                ans += find(xi, yi);
            }
        }
        return ans;
    }

    //让它无路可走
    private boolean block(int x, int y) {
        if (vis[x][y]) {
            return false;
        }
        vis[x][y] = true;
        if (maze[x][y] == '#') {
            return false;
        } else if (maze[x][y] == 'B') {
            return true;
        }


        for (int i = 0; i < 4; i++) {
            int xi = x + nx[i];
            int yi = y + ny[i];
            if (xi >= 0 && xi < n && yi >= 0 && yi < m && !vis[xi][yi] && maze[xi][yi] != '#') {
                if (maze[xi][yi] == 'B') {
                    if (maze[x][y] == '.') { //change
                        maze[x][y] = '#';
                    } else if (maze[x][y] == 'G') { //can't change
                        return true;
                    }
                    // no other
                } else { //A or .
                    if (block(xi, yi)) {
                        return true;
                    }
                }
            }
        }
        return false;
    }

    private void init() {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < m; j++) {
                vis[i][j] = false;
            }
        }
    }

    class Pair {
        int x;
        int y;

        Pair(int x, int y) {
            this.x = x;
            this.y = y;
        }

        @Override
        public String toString() {
            return "x: " + x + ", y: " + y;
        }
    }

    public static long invl(long a, long mod) {
        long b = mod;
        long p = 1, q = 0;
        while (b > 0) {
            long c = a / b;
            long d;
            d = a;
            a = b;
            b = d % b;
            d = p;
            p = q;
            q = d - c * q;
        }
        return p < 0 ? p + mod : p;
    }


    void run() throws Exception {

        is = oj ? System.in : new FileInputStream(INPUT_FILE_NAME);
        out = new PrintWriter(System.out);

        long s = System.currentTimeMillis();
        solve();
        out.flush();
        debug(System.currentTimeMillis() - s + "ms");
    }

    public static void main(String[] args) throws Exception {
        new D().run();
    }

    private byte[] inbuf = new byte[1024];
    int lenbuf = 0;
    int ptrbuf = 0;

    private int readByte() {
        if (lenbuf == -1) throw new InputMismatchException();
        if (ptrbuf >= lenbuf) {
            ptrbuf = 0;
            try {
                lenbuf = is.read(inbuf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (lenbuf <= 0) return -1;
        }
        return inbuf[ptrbuf++];
    }

    private boolean isSpaceChar(int c) {
        return !(c >= 33 && c <= 126);
    }

    private int skip() {
        int b;
        while ((b = readByte()) != -1 && isSpaceChar(b)) ;
        return b;
    }

    private double nd() {
        return Double.parseDouble(ns());
    }

    private char nc() {
        return (char) skip();
    }

    private String ns() {
        int b = skip();
        StringBuilder sb = new StringBuilder();
        while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ')
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    private char[] ns(int n) {
        char[] buf = new char[n];
        int b = skip(), p = 0;
        while (p < n && !(isSpaceChar(b))) {
            buf[p++] = (char) b;
            b = readByte();
        }
        return n == p ? buf : Arrays.copyOf(buf, p);
    }

    private char[][] nm(int n, int m) {
        char[][] map = new char[n][];
        for (int i = 0; i < n; i++) map[i] = ns(m);
        return map;
    }

    private int[] na(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++) a[i] = ni();
        return a;
    }

    private int ni() {
        int num = 0, b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private long nl() {
        long num = 0;
        int b;
        boolean minus = false;
        while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ;
        if (b == '-') {
            minus = true;
            b = readByte();
        }

        while (true) {
            if (b >= '0' && b <= '9') {
                num = num * 10 + (b - '0');
            } else {
                return minus ? -num : num;
            }
            b = readByte();
        }
    }

    private boolean oj = System.getProperty("ONLINE_JUDGE") != null;

    private void debug(Object... o) {
        if (!oj) System.out.println(Arrays.deepToString(o));
    }

    private void debug(Object a, Object o) {
        if (!oj) {
            System.out.println(a.toString() + ": " + o.toString());
        }
    }
}