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.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PrintWriter;
import java.util.HashMap;
import java.util.HashSet;
import java.util.PriorityQueue;
import java.util.TreeSet;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.Vector;

import static java.util.Collections.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class cf {

    private static final int MOD = (int) (1e9 + 7), MOD_FFT = 998244353;
    private static Scanner in;
    private static final Reader r = new Reader();
    private static final PrintWriter out = new PrintWriter(new BufferedOutputStream(System.out));
    private static final boolean thread = false, FASTIO = true;

    public static void main(final String[] args) throws Exception {
        if (!thread) {
            final int testcases = HAS_TEST_CASES ? ni() : 1;
            for (int i = 1; i <= testcases; i++) {
                // out.print("Case #" + (i + 1) + ": ");
                try {
                    solve();
                } catch (final Exception e) {
                    pn(e.getMessage());
                    pni("idk Exception");
                    e.printStackTrace(System.err);
                    System.exit(0);
                }
            }
            out.flush();
        }
    }

    static final boolean HAS_TEST_CASES = true;
    static final int SCAN_LINE_LENGTH = 1000002;

    static int n, a[], b[], e[][];

    private static Vector<Integer> adj[], v = new Vector<>();

    static void solve() throws Exception {
        int n = ni(), m = ni();
        char s[][] = new char[n][m];
        int v[][] = new int[n][m];
        for (int i = 0; i < s.length; i++) {
            s[i] = n().trim().toCharArray();
        }
        for (int i = 0; i < s.length; i++) {
            for (int j = 0; j < s[0].length; j++) {
                if (v[i][j] == 1)
                    continue;
                if (s[i][j] == 'B')
                    dfs(s, v, i, j);
            }
        }
        v = new int[n][m];
        reversedfs(s, v, n - 1, m - 1);
        for (int i = 0; i < v.length; i++) {
            for (int j = 0; j < v[0].length; j++) {
                if (v[i][j] == 1 && s[i][j] == 'B') {
                    pn("No");
                    return;
                }
                if (v[i][j] == 0 && s[i][j] == 'G') {
                    pn("No");
                    return;
                }
            }
        }
        pn("Yes");
    }

    private static void reversedfs(char[][] s, int[][] v, int i, int j) {
        if (i < 0 || j < 0 || i >= s.length || j >= s[0].length || s[i][j] == '#')
            return;
        if (v[i][j] == 1)
            return;
        v[i][j] = 1;
        reversedfs(s, v, i + 1, j);
        reversedfs(s, v, i, j + 1);
        reversedfs(s, v, i - 1, j);
        reversedfs(s, v, i, j - 1);
    }

    private static void dfs(char[][] s, int[][] v, int i, int j) {
        if (i < 0 || j < 0 || i >= s.length || j >= s[0].length || s[i][j] == 'G' || s[i][j] == '#')
            return;
        if (s[i][j] == 'B' && v[i][j] == 1)
            return;
        v[i][j] = 1;
        if (s[i][j] == '.') {
            s[i][j] = '#';
            return;
        }
        dfs(s, v, i + 1, j);
        dfs(s, v, i, j + 1);
        dfs(s, v, i - 1, j);
        dfs(s, v, i, j - 1);
    }

    private static void swap(final int i, final int j) {
        final int temp = a[i];
        a[i] = a[j];
        a[j] = temp;
    }

    private static void swapb(final int i, final int j) {
        final int temp = b[i];
        b[i] = b[j];
        b[j] = temp;
    }

    private static boolean isMulOverflow(final long A, final long B) {
        if (A == 0 || B == 0)
            return false;
        final long result = A * B;
        if (A == result / B)
            return true;
        return false;
    }

    private static int gcd(final int a, final int b) {
        if (b == 0)
            return a;
        return gcd(b, a % b);
    }

    private static class Pair<T, E> implements Comparable<Pair<T, E>> {
        T fir;
        E snd;

        Pair() {
        }

        Pair(final T x, final E y) {
            this.fir = x;
            this.snd = y;
        }

        @Override
        @SuppressWarnings("unchecked")
        public int compareTo(final Pair<T, E> o) {
            final int c = ((Comparable<T>) fir).compareTo(o.fir);
            return c != 0 ? c : ((Comparable<E>) snd).compareTo(o.snd);
        }

    }

    private static class pi implements Comparable<pi> {
        int fir, snd;

        pi() {
        }

        pi(final int a, final int b) {
            fir = a;
            snd = b;
        }

        public int compareTo(final pi o) {
            return fir == o.fir ? snd - o.snd : fir - o.fir;
        }

    }

    private static <T> void checkV(final Vector<T> adj[], final int i) {
        adj[i] = adj[i] == null ? new Vector<>() : adj[i];
    }

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

    private static int[] na1(final int n) throws Exception {
        final int[] a = new int[n + 1];
        for (int i = 1; i < a.length; i++) {
            a[i] = ni();
        }
        return a;
    }

    private static String n() throws IOException {
        return FASTIO ? r.readToken() : in.next();
    }

    private static String nln() throws IOException {
        return FASTIO ? r.readLine() : in.nextLine();
    }

    private static int ni() throws IOException {
        return FASTIO ? r.nextInt() : in.nextInt();
    }

    private static long nl() throws IOException {
        return FASTIO ? r.nextLong() : in.nextLong();
    }

    private static double nd() throws IOException {
        return FASTIO ? r.nextDouble() : in.nextDouble();
    }

    private static void p(final Object o) {
        out.print(o);
    }

    private static void pn(final Object o) {
        out.println(o);
    }

    private static void pn() {
        out.println("");
    }

    private static void pni(final Object o) {
        out.println(o);
        out.flush();
    }

    private static class Reader {
        private final int BUFFER_SIZE = 1 << 19;
        private final DataInputStream din;
        private final byte[] buffer;
        private int bufferPointer, bytesRead;
        private StringTokenizer st;
        private final BufferedReader br;

        public Reader() {
            din = new DataInputStream(System.in);
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public Reader(final String file_name) throws IOException {
            din = new DataInputStream(new FileInputStream(file_name));
            br = new BufferedReader(new FileReader(file_name));
            buffer = new byte[BUFFER_SIZE];
            bufferPointer = bytesRead = 0;
        }

        public String next() throws Exception {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (final IOException e) {
                    throw new Exception(e.toString());
                }
            }
            return st.nextToken();
        }

        public String nextLine() throws Exception {
            String str = "";
            try {
                str = br.readLine();
            } catch (final IOException e) {
                throw new Exception(e.toString());
            }
            return str;
        }

        final byte[] buf = new byte[SCAN_LINE_LENGTH];

        public String readLine() throws IOException {
            int cnt = 0;
            int c;
            while ((c = read()) != -1) {
                if (c == '\n')
                    if (cnt == 0)
                        continue;
                    else
                        break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public String readToken() throws IOException {
            int cnt = 0;
            int c;
            while ((c = read()) != -1) {
                if (c == '\n' || c == ' ')
                    if (cnt == 0)
                        continue;
                    else
                        break;
                buf[cnt++] = (byte) c;
            }
            return new String(buf, 0, cnt);
        }

        public int nextInt() throws IOException {
            int ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            final boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (neg)
                return -ret;
            return ret;
        }

        public long nextLong() throws IOException {
            long ret = 0;
            byte c = read();
            while (c <= ' ')
                c = read();
            final boolean neg = (c == '-');
            if (neg)
                c = read();
            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');
            if (neg)
                return -ret;
            return ret;
        }

        public double nextDouble() throws IOException {
            double ret = 0, div = 1;
            byte c = read();
            while (c <= ' ')
                c = read();
            final boolean neg = (c == '-');
            if (neg)
                c = read();

            do {
                ret = ret * 10 + c - '0';
            } while ((c = read()) >= '0' && c <= '9');

            if (c == '.') {
                while ((c = read()) >= '0' && c <= '9') {
                    ret += (c - '0') / (div *= 10);
                }
            }

            if (neg)
                return -ret;
            return ret;
        }

        private void fillBuffer() throws IOException {
            bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
            if (bytesRead == -1)
                buffer[0] = -1;
        }

        private byte read() throws IOException {
            if (bufferPointer == bytesRead)
                fillBuffer();
            return buffer[bufferPointer++];
        }

        public void close() throws IOException {
            if (din == null)
                return;
            din.close();
        }
    }

    static {
        if (!FASTIO)
            in = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        if (thread)
            new Thread(null, new Runnable() {
                @Override
                public void run() {
                    try {
                        final int testcases = HAS_TEST_CASES ? ni() : 1;
                        for (int i = 1; i <= testcases; i++) {
                            // out.print("Case #" + (i + 1) + ": ");
                            try {
                                solve();
                            } catch (final ArrayIndexOutOfBoundsException e) {
                                e.printStackTrace(System.err);
                                System.exit(-1);
                            } catch (final Exception e) {
                                pni("idk Exception in solve");
                                e.printStackTrace(System.err);
                                System.exit(-1);
                            }
                        }
                        out.flush();
                    } catch (final Throwable t) {
                        t.printStackTrace(System.err);
                        System.exit(-1);
                    }
                }
            }, "rec", (1L << 28)).start();
    }

    @SuppressWarnings({ "unchecked" })
    private static <T> T deepCopy(final T old) {
        try {
            return (T) deepCopyObject(old);
        } catch (final IOException | ClassNotFoundException e) {
            e.printStackTrace();
            System.exit(-1);
        }
        return null;
    }

    private static Object deepCopyObject(final Object oldObj) throws IOException, ClassNotFoundException {
        ObjectOutputStream oos = null;
        ObjectInputStream ois = null;
        try {
            final ByteArrayOutputStream bos = new ByteArrayOutputStream(); // A
            oos = new ObjectOutputStream(bos); // B
            // serialize and pass the object
            oos.writeObject(oldObj); // C
            oos.flush(); // D
            final ByteArrayInputStream bin = new ByteArrayInputStream(bos.toByteArray()); // E
            ois = new ObjectInputStream(bin); // F
            // return the new object
            return ois.readObject(); // G
        } catch (final ClassNotFoundException e) {
            pni("Exception in ObjectCloner = " + e);
            throw (e);
        } finally {
            oos.close();
            ois.close();
        }
    }

}