import java.io.*;
import java.util.*;
import java.lang.*;

public class c1 {
    public static MyScanner scan;
    public static PrintWriter out;
    public static void main(String[] args) {
        scan=new MyScanner();
        out=new PrintWriter(new BufferedOutputStream(System.out));

//        int t=1;
        int t=scan.nextInt();
        while(t-->0) {

            n=scan.nextInt();
            m=scan.nextInt();
            s=new char[n][m];
            boolean good=false,bad=false;
            ArrayList<Node> list=new ArrayList<>();
            for(int i=0;i<n;i++) {
                String temp=scan.nextLine();
                for(int j=0;j<m;j++) {
                    s[i][j]=temp.charAt(j);
                    if(s[i][j]=='B') bad=true;
                    else if(s[i][j]=='G') {
                        good=true;
                        list.add(new Node(i,j));
                    }
                }
            }

            if(!good&&!bad) out.println("YES");
            else if(bad&&!good) out.println((s[n-1][m-1]=='B')?"NO":"YES");
            else {
                if(bad) {
                    for(int i=0;i<n;i++) {
                        for(int j=0;j<m;j++) {
                            if(s[i][j]=='B') {
                                if(i-1>=0&&s[i-1][j]=='.') s[i-1][j]='#';
                                if(j-1>=0&&s[i][j-1]=='.') s[i][j-1]='#';
                                if(i+1<n&&s[i+1][j]=='.') s[i+1][j]='#';
                                if(j+1<m&&s[i][j+1]=='.') s[i][j+1]='#';
                            }
                        }
                    }
                }
                boolean ans=true;
                for(int c=0;c<list.size();c++) {
                    if(!bfs(list.get(c),new boolean[n][m])) {
                        ans=false;
                        break;
                    }
                }
                out.println((ans)?"YES":"NO");
            }
        }
        out.close();
    }

    //-----------------------------------------------------HERE---------------------------------------------------------

    static class Node implements Comparable<Node> {
        private int x,y;
        public Node(int x,int y) {
            this.x=x;
            this.y=y;
        }

        public int compareTo(Node other) {
            if(this.x==other.x) return 0;
            else if(this.x>other.x) return 1;
            else return -1;
        }

        public boolean equals(Node other) {
            return this.x==other.x&&this.y==other.y;
        }
    }

    public static char[][] s;
    public static int n,m;

    public static boolean bfs(Node parent,boolean[][] visited) {
        Queue<Node> que=new LinkedList<>();
        visited[parent.x][parent.y]=true;
        que.add(parent);
        while(que.size()>0) {
            int size=que.size();
            while(size-->0) {
                Node tempdes=que.poll();
                int x=tempdes.x,y=tempdes.y;
                visited[x][y]=true;
                if(x==n-1&&y==m-1) return true;
                if(x-1>=0&&s[x-1][y]!='#'&&visited[x-1][y]!=true) que.add(new Node(x-1,y));
                if(y-1>=0&&s[x][y-1]!='#'&&visited[x][y-1]!=true) que.add(new Node(x,y-1));
                if(x+1<n&&s[x+1][y]!='#'&&visited[x+1][y]!=true) que.add(new Node(x+1,y));
                if(y+1<m&&s[x][y+1]!='#'&&visited[x][y+1]!=true) que.add(new Node(x,y+1));
            }
        }
        return false;
    }

    //------------------------------------------------------------------------------------------------------------------

    //util
    public static int gcd(int a, int b) {
        if (b == 0)
            return a;
        if (a == 0)
            return b;
        return (a > b) ? gcd(a % b, b) : gcd(a, b % a);
    }

    public static int lcm(int a, int b) {
        return a * b / gcd(a, b);
    }

    public static ArrayList<Integer> getPrimes(int n) {
        boolean prime[]=new boolean[n+1];
        Arrays.fill(prime,true);
        for (int p=2;p*p<=n;p++) {
            if (prime[p]) {
                for (int i=p*2;i<=n;i+=p) {
                    prime[i]=false;
                }
            }
        }
        ArrayList<Integer> primeNumbers=new ArrayList<Integer>();
        for (int i = 2; i <= n; i++) {
            if (prime[i]) {
                primeNumbers.add(i);
            }
        }
        return primeNumbers;
    }

    public static boolean isPrime(int a) {
        if (a == 0 || a == 1) {
            return false;
        }
        if (a == 2) {
            return true;
        }
        for (int i = 2; i < Math.sqrt(a) + 1; i++) {
            if (a % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static ArrayList<Integer> getDivisors(int n) {
        ArrayList<Integer> div = new ArrayList<Integer>();
        for (int i=1;i*i<=n;i++) {
            if (n%i==0) {
                div.add(i);
                if (n/i!=i)
                    div.add(n/i);
            }
        }
        return div;
    }

    //scanner
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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


import java.io.*;
import java.util.*;
import java.lang.*;

public class c1 {
    public static MyScanner scan;
    public static PrintWriter out;
    public static void main(String[] args) {
        scan=new MyScanner();
        out=new PrintWriter(new BufferedOutputStream(System.out));

//        int t=1;
        int t=scan.nextInt();
        while(t-->0) {

            n=scan.nextInt();
            m=scan.nextInt();
            s=new char[n][m];
            boolean good=false,bad=false;
            ArrayList<Node> list=new ArrayList<>(),blist=new ArrayList<>();
            for(int i=0;i<n;i++) {
                String temp=scan.nextLine();
                for(int j=0;j<m;j++) {
                    s[i][j]=temp.charAt(j);
                    if(s[i][j]=='B') {
                        bad=true;
                        blist.add(new Node(i,j));
                    }
                    else if(s[i][j]=='G') {
                        good=true;
                        list.add(new Node(i,j));
                    }
                }
            }

            if(!good&&!bad) out.println("YES");
            else if(bad&&!good) out.println((s[n-1][m-1]=='B')?"NO":"YES");
            else {
                boolean stack=false;
                if(bad) {
                    for(int c=0;c<blist.size();c++) {
                        Node temp=blist.get(c);
                        int i=temp.x,j=temp.y;
                        if(s[i][j]=='B') {
                            if((i-1>0&&s[i-1][j]=='G')||(j-1>0&&s[i][j-1]=='G')||(i+1<n&&s[i+1][j]=='G')||(j+1<m&&s[i][j+1]=='G')) {
                                stack=true;
                            } else {
                                if(i-1>=0&&s[i-1][j]=='.') s[i-1][j]='#';
                                if(j-1>=0&&s[i][j-1]=='.') s[i][j-1]='#';
                                if(i+1<n&&s[i+1][j]=='.') s[i+1][j]='#';
                                if(j+1<m&&s[i][j+1]=='.') s[i][j+1]='#';
                            }
                        }
                    }
                }
                if(stack) out.println("NO");
                else {
                    visited=new boolean[n][m];
                    if(s[n-1][m-1]!='#'&&s[n-1][m-1]!='B') bfs();
                    boolean ans=true;
                    for(int c=0;c<list.size();c++) {
                        if(visited[list.get(c).x][list.get(c).y]!=true) {
                            ans=false;
                            break;
                        }
                    }
                    out.println((ans)?"YES":"NO");
                }
            }
        }
        out.close();
    }

    //-----------------------------------------------------HERE---------------------------------------------------------

    static class Node implements Comparable<Node> {
        private int x,y;
        public Node(int x,int y) {
            this.x=x;
            this.y=y;
        }

        public int compareTo(Node other) {
            if(this.x==other.x) return 0;
            else if(this.x>other.x) return 1;
            else return -1;
        }

        public boolean equals(Node other) {
            return this.x==other.x&&this.y==other.y;
        }
    }

    public static char[][] s;
    public static int n,m;
    public static boolean[][] visited;

    public static void bfs() {
        Queue<Node> que=new LinkedList<>();
        visited[n-1][m-1]=true;
        que.add(new Node(n-1,m-1));
        while(que.size()>0) {
            int size=que.size();
            while(size-->0) {
                Node tempdes=que.poll();
                int x=tempdes.x,y=tempdes.y;
                if(x-1>=0&&s[x-1][y]!='#'&&visited[x-1][y]!=true) {
                    que.add(new Node(x-1,y));
                    visited[x-1][y]=true;
                }
                if(y-1>=0&&s[x][y-1]!='#'&&visited[x][y-1]!=true) {
                    que.add(new Node(x,y-1));
                    visited[x][y-1]=true;
                }
                if(x+1<n&&s[x+1][y]!='#'&&visited[x+1][y]!=true) {
                    que.add(new Node(x+1,y));
                    visited[x+1][y]=true;
                }
                if(y+1<m&&s[x][y+1]!='#'&&visited[x][y+1]!=true) {
                    que.add(new Node(x,y+1));
                    visited[x][y+1]=true;
                }
            }
        }
    }

    //------------------------------------------------------------------------------------------------------------------

    //util
    public static int gcd(int a, int b) {
        if (b == 0)
            return a;
        if (a == 0)
            return b;
        return (a > b) ? gcd(a % b, b) : gcd(a, b % a);
    }

    public static int lcm(int a, int b) {
        return a * b / gcd(a, b);
    }

    public static ArrayList<Integer> getPrimes(int n) {
        boolean prime[]=new boolean[n+1];
        Arrays.fill(prime,true);
        for (int p=2;p*p<=n;p++) {
            if (prime[p]) {
                for (int i=p*2;i<=n;i+=p) {
                    prime[i]=false;
                }
            }
        }
        ArrayList<Integer> primeNumbers=new ArrayList<Integer>();
        for (int i = 2; i <= n; i++) {
            if (prime[i]) {
                primeNumbers.add(i);
            }
        }
        return primeNumbers;
    }

    public static boolean isPrime(int a) {
        if (a == 0 || a == 1) {
            return false;
        }
        if (a == 2) {
            return true;
        }
        for (int i = 2; i < Math.sqrt(a) + 1; i++) {
            if (a % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static ArrayList<Integer> getDivisors(int n) {
        ArrayList<Integer> div = new ArrayList<Integer>();
        for (int i=1;i*i<=n;i++) {
            if (n%i==0) {
                div.add(i);
                if (n/i!=i)
                    div.add(n/i);
            }
        }
        return div;
    }

    //scanner
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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


import java.io.*;
import java.util.*;
import java.lang.*;

public class c1 {
    public static MyScanner scan;
    public static PrintWriter out;
    public static void main(String[] args) {
        scan=new MyScanner();
        out=new PrintWriter(new BufferedOutputStream(System.out));

//        int t=1;
        int t=scan.nextInt();
        while(t-->0) {

            n=scan.nextInt();
            m=scan.nextInt();
            s=new char[n][m];
            boolean good=false,bad=false;
            ArrayList<Node> list=new ArrayList<>(),blist=new ArrayList<>();
            for(int i=0;i<n;i++) {
                String temp=scan.nextLine();
                for(int j=0;j<m;j++) {
                    s[i][j]=temp.charAt(j);
                    if(s[i][j]=='B') {
                        bad=true;
                        blist.add(new Node(i,j));
                    }
                    else if(s[i][j]=='G') {
                        good=true;
                        list.add(new Node(i,j));
                    }
                }
            }

            if(!good&&!bad) out.println("YES");
            else if(bad&&!good) out.println((s[n-1][m-1]=='B')?"NO":"YES");
            else {
                boolean stack=false;
                if(bad) {
                    for(int c=0;c<blist.size();c++) {
                        Node temp=blist.get(c);
                        int i=temp.x,j=temp.y;
                        if(s[i][j]=='B') {
                            if((i-1>0&&s[i-1][j]=='G')||(j-1>0&&s[i][j-1]=='G')||(i+1<n&&s[i+1][j]=='G')||(j+1<m&&s[i][j+1]=='G')) {
                                stack=true;
                            } else {
                                if(i-1>=0&&s[i-1][j]=='.') s[i-1][j]='#';
                                if(j-1>=0&&s[i][j-1]=='.') s[i][j-1]='#';
                                if(i+1<n&&s[i+1][j]=='.') s[i+1][j]='#';
                                if(j+1<m&&s[i][j+1]=='.') s[i][j+1]='#';
                            }
                        }
                    }
                }
                if(stack) out.println("NO");
                else {
                    visited=new boolean[n][m];
                    if(s[n-1][m-1]=='.') bfs();
                    boolean ans=true;
                    for(int c=0;c<list.size();c++) {
                        if(visited[list.get(c).x][list.get(c).y]!=true) {
                            ans=false;
                            break;
                        }
                    }
                    out.println((ans)?"YES":"NO");
                }
            }
        }
        out.close();
    }

    //-----------------------------------------------------HERE---------------------------------------------------------

    static class Node implements Comparable<Node> {
        private int x,y;
        public Node(int x,int y) {
            this.x=x;
            this.y=y;
        }

        public int compareTo(Node other) {
            if(this.x==other.x) return 0;
            else if(this.x>other.x) return 1;
            else return -1;
        }

        public boolean equals(Node other) {
            return this.x==other.x&&this.y==other.y;
        }
    }

    public static char[][] s;
    public static int n,m;
    public static boolean[][] visited;

    public static void bfs() {
        Queue<Node> que=new LinkedList<>();
        visited[n-1][m-1]=true;
        que.add(new Node(n-1,m-1));
        while(que.size()>0) {
            int size=que.size();
            while(size-->0) {
                Node tempdes=que.poll();
                int x=tempdes.x,y=tempdes.y;
                visited[x][y]=true;
                if(x-1>=0&&s[x-1][y]!='#'&&visited[x-1][y]!=true) que.add(new Node(x-1,y));
                if(y-1>=0&&s[x][y-1]!='#'&&visited[x][y-1]!=true) que.add(new Node(x,y-1));
                if(x+1<n&&s[x+1][y]!='#'&&visited[x+1][y]!=true) que.add(new Node(x+1,y));
                if(y+1<m&&s[x][y+1]!='#'&&visited[x][y+1]!=true) que.add(new Node(x,y+1));
            }
        }
    }

    //------------------------------------------------------------------------------------------------------------------

    //util
    public static int gcd(int a, int b) {
        if (b == 0)
            return a;
        if (a == 0)
            return b;
        return (a > b) ? gcd(a % b, b) : gcd(a, b % a);
    }

    public static int lcm(int a, int b) {
        return a * b / gcd(a, b);
    }

    public static ArrayList<Integer> getPrimes(int n) {
        boolean prime[]=new boolean[n+1];
        Arrays.fill(prime,true);
        for (int p=2;p*p<=n;p++) {
            if (prime[p]) {
                for (int i=p*2;i<=n;i+=p) {
                    prime[i]=false;
                }
            }
        }
        ArrayList<Integer> primeNumbers=new ArrayList<Integer>();
        for (int i = 2; i <= n; i++) {
            if (prime[i]) {
                primeNumbers.add(i);
            }
        }
        return primeNumbers;
    }

    public static boolean isPrime(int a) {
        if (a == 0 || a == 1) {
            return false;
        }
        if (a == 2) {
            return true;
        }
        for (int i = 2; i < Math.sqrt(a) + 1; i++) {
            if (a % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static ArrayList<Integer> getDivisors(int n) {
        ArrayList<Integer> div = new ArrayList<Integer>();
        for (int i=1;i*i<=n;i++) {
            if (n%i==0) {
                div.add(i);
                if (n/i!=i)
                    div.add(n/i);
            }
        }
        return div;
    }

    //scanner
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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


import java.io.*;
import java.util.*;
import java.lang.*;

public class c1 {
    public static MyScanner scan;
    public static PrintWriter out;
    public static void main(String[] args) {
        scan=new MyScanner();
        out=new PrintWriter(new BufferedOutputStream(System.out));

//        int t=1;
        int t=scan.nextInt();
        while(t-->0) {

            n=scan.nextInt();
            m=scan.nextInt();
            s=new char[n][m];
            boolean good=false,bad=false;
            ArrayList<Node> list=new ArrayList<>();
            for(int i=0;i<n;i++) {
                String temp=scan.nextLine();
                for(int j=0;j<m;j++) {
                    s[i][j]=temp.charAt(j);
                    if(s[i][j]=='B') bad=true;
                    else if(s[i][j]=='G') {
                        good=true;
                        list.add(new Node(i,j));
                    }
                }
            }

            if(!good&&!bad) out.println("YES");
            else if(bad&&!good) out.println((s[n-1][m-1]=='B')?"NO":"YES");
            else {
                boolean stack=false;
                if(bad) {
                    for(int i=0;i<n;i++) {
                        for(int j=0;j<m;j++) {
                            if(s[i][j]=='B') {
                                if((i-1>0&&s[i-1][j]=='G')||(j-1>0&&s[i][j-1]=='G')||(i+1<n&&s[i+1][j]=='G')||(j+1<m&&s[i][j+1]=='G')) {
                                    stack=true;
                                } else {
                                    if(i-1>=0&&s[i-1][j]=='.') s[i-1][j]='#';
                                    if(j-1>=0&&s[i][j-1]=='.') s[i][j-1]='#';
                                    if(i+1<n&&s[i+1][j]=='.') s[i+1][j]='#';
                                    if(j+1<m&&s[i][j+1]=='.') s[i][j+1]='#';
                                }
                            }
                        }
                    }
                }
                if(stack) out.println("NO");
                else {
                    visited=new boolean[n][m];
                    if(s[n-1][m-1]=='.') bfs();
                    boolean ans=true;
                    for(int c=0;c<list.size();c++) {
                        if(visited[list.get(c).x][list.get(c).y]!=true) {
                            ans=false;
                            break;
                        }
                    }
                    out.println((ans)?"YES":"NO");
                }
            }
        }
        out.close();
    }

    //-----------------------------------------------------HERE---------------------------------------------------------

    static class Node implements Comparable<Node> {
        private int x,y;
        public Node(int x,int y) {
            this.x=x;
            this.y=y;
        }

        public int compareTo(Node other) {
            if(this.x==other.x) return 0;
            else if(this.x>other.x) return 1;
            else return -1;
        }

        public boolean equals(Node other) {
            return this.x==other.x&&this.y==other.y;
        }
    }

    public static char[][] s;
    public static int n,m;
    public static boolean[][] visited;

    public static void bfs() {
        Queue<Node> que=new LinkedList<>();
        visited[n-1][m-1]=true;
        que.add(new Node(n-1,m-1));
        while(que.size()>0) {
            int size=que.size();
            while(size-->0) {
                Node tempdes=que.poll();
                int x=tempdes.x,y=tempdes.y;
                visited[x][y]=true;
                if(x-1>=0&&s[x-1][y]!='#'&&visited[x-1][y]!=true) que.add(new Node(x-1,y));
                if(y-1>=0&&s[x][y-1]!='#'&&visited[x][y-1]!=true) que.add(new Node(x,y-1));
                if(x+1<n&&s[x+1][y]!='#'&&visited[x+1][y]!=true) que.add(new Node(x+1,y));
                if(y+1<m&&s[x][y+1]!='#'&&visited[x][y+1]!=true) que.add(new Node(x,y+1));
            }
        }
    }

    //------------------------------------------------------------------------------------------------------------------

    //util
    public static int gcd(int a, int b) {
        if (b == 0)
            return a;
        if (a == 0)
            return b;
        return (a > b) ? gcd(a % b, b) : gcd(a, b % a);
    }

    public static int lcm(int a, int b) {
        return a * b / gcd(a, b);
    }

    public static ArrayList<Integer> getPrimes(int n) {
        boolean prime[]=new boolean[n+1];
        Arrays.fill(prime,true);
        for (int p=2;p*p<=n;p++) {
            if (prime[p]) {
                for (int i=p*2;i<=n;i+=p) {
                    prime[i]=false;
                }
            }
        }
        ArrayList<Integer> primeNumbers=new ArrayList<Integer>();
        for (int i = 2; i <= n; i++) {
            if (prime[i]) {
                primeNumbers.add(i);
            }
        }
        return primeNumbers;
    }

    public static boolean isPrime(int a) {
        if (a == 0 || a == 1) {
            return false;
        }
        if (a == 2) {
            return true;
        }
        for (int i = 2; i < Math.sqrt(a) + 1; i++) {
            if (a % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static ArrayList<Integer> getDivisors(int n) {
        ArrayList<Integer> div = new ArrayList<Integer>();
        for (int i=1;i*i<=n;i++) {
            if (n%i==0) {
                div.add(i);
                if (n/i!=i)
                    div.add(n/i);
            }
        }
        return div;
    }

    //scanner
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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


import java.io.*;
import java.util.*;
import java.lang.*;

public class c1 {
    public static MyScanner scan;
    public static PrintWriter out;
    public static void main(String[] args) {
        scan=new MyScanner();
        out=new PrintWriter(new BufferedOutputStream(System.out));

//        int t=1;
        int t=scan.nextInt();
        while(t-->0) {

            n=scan.nextInt();
            m=scan.nextInt();
            s=new char[n][m];
            boolean good=false,bad=false;
            ArrayList<Node> list=new ArrayList<>();
            for(int i=0;i<n;i++) {
                String temp=scan.nextLine();
                for(int j=0;j<m;j++) {
                    s[i][j]=temp.charAt(j);
                    if(s[i][j]=='B') bad=true;
                    else if(s[i][j]=='G') {
                        good=true;
                        list.add(new Node(i,j));
                    }
                }
            }

            if(!good&&!bad) out.println("YES");
            else if(bad&&!good) out.println((s[n-1][m-1]=='B')?"NO":"YES");
            else {
                boolean stack=false;
                if(bad) {
                    for(int i=0;i<n;i++) {
                        for(int j=0;j<m;j++) {
                            if(s[i][j]=='B') {
                                if((i-1>0&&s[i-1][j]=='G')||(j-1>0&&s[i][j-1]=='G')||(i+1<n&&s[i+1][j]=='G')||(j+1<m&&s[i][j+1]=='G')) {
                                    stack=true;
                                } else {
                                    if(i-1>0&&s[i-1][j]=='.') s[i-1][j]='#';
                                    if(j-1>0&&s[i][j-1]=='.') s[i][j-1]='#';
                                    if(i+1<n&&s[i+1][j]=='.') s[i+1][j]='#';
                                    if(j+1<m&&s[i][j+1]=='.') s[i][j+1]='#';
                                }
                            }
                        }
                    }
                }
                if(stack) out.println("NO");
                else {
                    boolean ans=true;
                    for(int c=0;c<list.size();c++) {
                        if(!bfs(list.get(c),new boolean[n][m])) {
                            ans=false;
                            break;
                        }
                    }
                    out.println((ans)?"YES":"NO");
                }
            }
        }
        out.close();
    }

    //-----------------------------------------------------HERE---------------------------------------------------------

    static class Node implements Comparable<Node> {
        private int x,y;
        public Node(int x,int y) {
            this.x=x;
            this.y=y;
        }

        public int compareTo(Node other) {
            if(this.x==other.x) return 0;
            else if(this.x>other.x) return 1;
            else return -1;
        }

        public boolean equals(Node other) {
            return this.x==other.x&&this.y==other.y;
        }
    }

    public static char[][] s;
    public static int n,m;

    public static boolean bfs(Node parent,boolean[][] visited) {
        Queue<Node> que=new LinkedList<>();
        visited[parent.x][parent.y]=true;
        que.add(parent);
        while(que.size()>0) {
            int size=que.size();
            while(size-->0) {
                Node tempdes=que.poll();
                int x=tempdes.x,y=tempdes.y;
                visited[x][y]=true;
                if(x==n-1&&y==m-1) return true;
                if(x-1>0&&s[x-1][y]!='#'&&visited[x-1][y]!=true) que.add(new Node(x-1,y));
                if(y-1>0&&s[x][y-1]!='#'&&visited[x][y-1]!=true) que.add(new Node(x,y-1));
                if(x+1<n&&s[x+1][y]!='#'&&visited[x+1][y]!=true) que.add(new Node(x+1,y));
                if(y+1<m&&s[x][y+1]!='#'&&visited[x][y+1]!=true) que.add(new Node(x,y+1));
            }
        }
        return false;
    }

    //------------------------------------------------------------------------------------------------------------------

    //util
    public static int gcd(int a, int b) {
        if (b == 0)
            return a;
        if (a == 0)
            return b;
        return (a > b) ? gcd(a % b, b) : gcd(a, b % a);
    }

    public static int lcm(int a, int b) {
        return a * b / gcd(a, b);
    }

    public static ArrayList<Integer> getPrimes(int n) {
        boolean prime[]=new boolean[n+1];
        Arrays.fill(prime,true);
        for (int p=2;p*p<=n;p++) {
            if (prime[p]) {
                for (int i=p*2;i<=n;i+=p) {
                    prime[i]=false;
                }
            }
        }
        ArrayList<Integer> primeNumbers=new ArrayList<Integer>();
        for (int i = 2; i <= n; i++) {
            if (prime[i]) {
                primeNumbers.add(i);
            }
        }
        return primeNumbers;
    }

    public static boolean isPrime(int a) {
        if (a == 0 || a == 1) {
            return false;
        }
        if (a == 2) {
            return true;
        }
        for (int i = 2; i < Math.sqrt(a) + 1; i++) {
            if (a % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static ArrayList<Integer> getDivisors(int n) {
        ArrayList<Integer> div = new ArrayList<Integer>();
        for (int i=1;i*i<=n;i++) {
            if (n%i==0) {
                div.add(i);
                if (n/i!=i)
                    div.add(n/i);
            }
        }
        return div;
    }

    //scanner
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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


import java.io.*;
import java.util.*;
import java.lang.*;

public class c1 {
    public static MyScanner scan;
    public static PrintWriter out;
    public static void main(String[] args) {
        scan=new MyScanner();
        out=new PrintWriter(new BufferedOutputStream(System.out));

//        int t=1;
        int t=scan.nextInt();
        while(t-->0) {

            n=scan.nextInt();
            m=scan.nextInt();
            s=new char[n][m];
            boolean goodd=false,badd=false;
            ArrayList<Node> list=new ArrayList<>();
            for(int i=0;i<n;i++) {
                String temp=scan.nextLine();
                for(int j=0;j<m;j++) {
                    s[i][j]=temp.charAt(j);
                    if(s[i][j]=='B') badd=true;
                    else if(s[i][j]=='G') {
                        goodd=true;
                        list.add(new Node(i,j));
                    }
                }
            }

            if(!goodd&&!badd) out.println("YES");
            else if(badd&&!goodd) out.println((s[n-1][m-1]=='B')?"NO":"YES");
            else {
                visited=new boolean[n][m];
                good=new boolean[n][m];
                if(s[n-1][m-1]=='.') bfs();
                boolean ans=true;
                for(int c=0;c<list.size();c++) {
                    if(good[list.get(c).x][list.get(c).y]!=true) {
                        ans=false;
                        break;
                    }
                }
                out.println((ans)?"YES":"NO");
            }
        }
        out.close();
    }

    //-----------------------------------------------------HERE---------------------------------------------------------

    static class Node implements Comparable<Node> {
        private int x,y;
        public Node(int x,int y) {
            this.x=x;
            this.y=y;
        }

        public int compareTo(Node other) {
            if(this.x==other.x) return 0;
            else if(this.x>other.x) return 1;
            else return -1;
        }

        public boolean equals(Node other) {
            return this.x==other.x&&this.y==other.y;
        }
    }

    public static char[][] s;
    public static int n,m;
    public static boolean[][] visited,good;

    public static void bfs() {
        Queue<Node> que=new LinkedList<>();
        que.add(new Node(n-1,m-1));
        while(que.size()>0) {
            int size=que.size();
            while(size-->0) {
                Node tempdes=que.poll();
                int x=tempdes.x,y=tempdes.y;
                visited[x][y]=true;
                good[x][y]=true;
                if(x-1>=0&&s[x-1][y]=='B')  {
                    good[x][y]=false;
                    good[x-1][y]=false;
                    visited[x-1][y]=true;
                }
                if(y-1>=0&&s[x][y-1]=='B') {
                    good[x][y]=false;
                    good[x][y-1]=false;
                    visited[x][y-1]=true;
                }
                if(x+1<n&&s[x+1][y]=='B') {
                    good[x][y]=false;
                    good[x+1][y]=false;
                    visited[x+1][y]=true;
                }
                if(y+1<m&&s[x][y+1]=='B') {
                    good[x][y]=false;
                    good[x][y+1]=false;
                    visited[x][y+1]=true;
                }

                if(!good[x][y]) continue;
                if(x-1>=0&&s[x-1][y]!='#'&&visited[x-1][y]!=true) que.add(new Node(x-1,y));
                if(y-1>=0&&s[x][y-1]!='#'&&visited[x][y-1]!=true) que.add(new Node(x,y-1));
                if(x+1<n&&s[x+1][y]!='#'&&visited[x+1][y]!=true) que.add(new Node(x+1,y));
                if(y+1<m&&s[x][y+1]!='#'&&visited[x][y+1]!=true) que.add(new Node(x,y+1));
            }
        }
    }

    //------------------------------------------------------------------------------------------------------------------

    //util
    public static int gcd(int a, int b) {
        if (b == 0)
            return a;
        if (a == 0)
            return b;
        return (a > b) ? gcd(a % b, b) : gcd(a, b % a);
    }

    public static int lcm(int a, int b) {
        return a * b / gcd(a, b);
    }

    public static ArrayList<Integer> getPrimes(int n) {
        boolean prime[]=new boolean[n+1];
        Arrays.fill(prime,true);
        for (int p=2;p*p<=n;p++) {
            if (prime[p]) {
                for (int i=p*2;i<=n;i+=p) {
                    prime[i]=false;
                }
            }
        }
        ArrayList<Integer> primeNumbers=new ArrayList<Integer>();
        for (int i = 2; i <= n; i++) {
            if (prime[i]) {
                primeNumbers.add(i);
            }
        }
        return primeNumbers;
    }

    public static boolean isPrime(int a) {
        if (a == 0 || a == 1) {
            return false;
        }
        if (a == 2) {
            return true;
        }
        for (int i = 2; i < Math.sqrt(a) + 1; i++) {
            if (a % i == 0) {
                return false;
            }
        }
        return true;
    }

    public static ArrayList<Integer> getDivisors(int n) {
        ArrayList<Integer> div = new ArrayList<Integer>();
        for (int i=1;i*i<=n;i++) {
            if (n%i==0) {
                div.add(i);
                if (n/i!=i)
                    div.add(n/i);
            }
        }
        return div;
    }

    //scanner
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

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


import java.io.*;
import java.util.*;

public class DCells {

  private static final String REGEX = " ";
  private static final Boolean DEBUG = false;
  private static final String FILE_NAME = "input.txt";

  public static void main(String[] args) throws IOException {
    if (DEBUG) {
      generate();
    }
    Solver solver = new Solver();
    solver.readData();
    solver.solve();
    solver.print();
  }

  private static void generate() throws IOException {
//    FileWriter writer = new FileWriter("input.txt");
//    writer.close();
  }

  private static class Data {
    int n, m;
    char[][] cell;
  }

  private static class Solver {
    private StringBuilder myStringBuilder = new StringBuilder();
    int t;
    Data[] data;

    void readData() throws IOException {
      Scanner scanner = new Scanner();
      t = scanner.nextInt();
      data = new Data[t];
      for (int i = 0; i < t; i++) {
        Data data = new Data();
        this.data[i] = data;
        data.n = scanner.nextInt();
        data.m = scanner.nextInt();
        data.cell = new char[data.n][data.m];
        for (int x = 0; x < data.n; x++) {
          String line = scanner.nextLine();
          for (int y = 0; y < data.m; y++) {
            data.cell[x][y] = line.charAt(y);
          }
        }
      }
      scanner.close();
    }

    void solve() {
      for (int i = 0; i < t; i++) {
        Data data = this.data[i];
        int goodCount = 0;
        char[][] cell = data.cell;
        int n = data.n;
        int m = data.m;
        for (int x = 0; x < n; x++) {
          for (int y = 0; y < m; y++) {
            if (cell[x][y] == 'G') {
              goodCount++;
            }
            if (cell[x][y] == 'B') {
              if (x > 0 && cell[x - 1][y] == '.') {
                cell[x - 1][y] = '#';
              }
              if (x < n - 1 && cell[x + 1][y] == '.') {
                cell[x + 1][y] = '#';
              }
              if (y > 0 && cell[x][y - 1] == '.') {
                cell[x][y - 1] = '#';
              }

              if (y < m - 1 && cell[x][y + 1] == '.') {
                cell[x][y + 1] = '#';
              }
            }
          }
        }
        if (goodCount == 0) {
          out("Yes");
          newLine();
          continue;
        }
        if (cell[n - 1][m - 1] == '#' || cell[n - 1][m - 1] == 'B') {
          out("No");
          newLine();
          continue;
        }

        Deque<Coord> deque = new ArrayDeque<>();
        Set<Coord> visited = new HashSet<>();
        Coord exit = new Coord(n - 1, m - 1);
        deque.push(exit);
        visited.add(exit);
        int freeGoods = 0;
        boolean result = false;
        while (!deque.isEmpty()) {
          Coord next = deque.pop();
          if (cell[next.x][next.y] == '#') {
            continue;
          }
          if (cell[next.x][next.y] == 'B') {
            break;
          }
          if (cell[next.x][next.y] == 'G') {
            freeGoods++;
            if (freeGoods == goodCount) {
              result = true;
              break;
            }
          }
          List<Coord> neighbours = neighbours(next, n, m);
          for (Coord neighbour : neighbours) {
            if (visited.contains(neighbour)) {
              continue;
            }
            deque.push(neighbour);
            visited.add(neighbour);
          }
        }
        if (result) {
          out("Yes");
        } else {
          out("No");
        }
        newLine();
      }
    }

    List<Coord> neighbours(Coord coord, int n, int m) {
      ArrayList<Coord> result = new ArrayList<>();
      if (coord.x > 0) {
        result.add(new Coord(coord.x - 1, coord.y));
      }
      if (coord.x < n - 1) {
        result.add(new Coord(coord.x + 1, coord.y));
      }
      if (coord.y > 0) {
        result.add(new Coord(coord.x, coord.y - 1));
      }

      if (coord.y < m - 1) {
        result.add(new Coord(coord.x, coord.y + 1));
      }
      return result;
    }

    static class Coord {
      int x;
      int y;

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

      @Override
      public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Coord pair = (Coord) o;
        return x == pair.x &&
            y == pair.y;
      }

      @Override
      public int hashCode() {
        return Objects.hash(x, y);
      }
    }

    void print() {
      System.out.println(myStringBuilder);
    }

    void out(Object object) {
      myStringBuilder.append(object);
    }

    void out(String string) {
      myStringBuilder.append(string);
    }

    public void out(boolean b) {
      myStringBuilder.append(b);
    }

    public void out(char c) {
      myStringBuilder.append(c);
    }

    public void out(int i) {
      myStringBuilder.append(i);
    }

    public void out(long lng) {
      myStringBuilder.append(lng);
    }

    public void out(float f) {
      myStringBuilder.append(f);
    }

    public void out(double d) {
      myStringBuilder.append(d);
    }

    public void newLine() {
      myStringBuilder.append("\n");
    }

    @SuppressWarnings("SameParameterValue")
    int[] splitInteger(String string, int n) {
      final String[] split = string.split(REGEX, n);
      int[] result = new int[split.length];
      for (int i = 0; i < n; ++i) {
        result[i] = Integer.parseInt(split[i]);
      }
      return result;
    }

    @SuppressWarnings("SameParameterValue")
    long[] splitLong(String string, int n) {
      final String[] split = string.split(REGEX, n);
      long[] result = new long[split.length];
      for (int i = 0; i < n; ++i) {
        result[i] = Long.parseLong(split[i]);
      }
      return result;
    }

    @SuppressWarnings("SameParameterValue")
    double[] splitDouble(String string, int n) {
      final String[] split = string.split(REGEX, n);
      double[] result = new double[split.length];
      for (int i = 0; i < n; ++i) {
        result[i] = Double.parseDouble(split[i]);
      }
      return result;
    }

    @SuppressWarnings("SameParameterValue")
    String[] splitString(String string, int n) {
      return string.split(REGEX, n);
    }

    public int max(int a, int b) {
      return Math.max(a, b);
    }

    public int max(int[] arr) {
      int max = Integer.MIN_VALUE;
      for (int x : arr) {
        max = max(max, x);
      }
      return max;
    }

    public long max(long a, long b) {
      return Math.max(a, b);
    }

    public int min(int a, int b) {
      return Math.min(a, b);
    }

    public long min(long a, long b) {
      return Math.min(a, b);
    }

    public double max(double a, double b) {
      return Math.max(a, b);
    }

    public double min(double a, double b) {
      return Math.min(a, b);
    }

    private final static int MOD = 1000000009;

    int multMod(int a, int b) {
      return ((a % MOD) * (b % MOD)) % MOD;
    }

    int sumMod(int a, int b) {
      return ((a % MOD) + (b % MOD)) % MOD;
    }

    long multMod(long a, long b) {
      return ((a % MOD) * (b % MOD)) % MOD;
    }

    long sumMod(long a, long b) {
      return ((a % MOD) + (b % MOD)) % MOD;
    }

    int sum(int[] arr) {
      int sum = 0;
      for (int item : arr) {
        sum += item;
      }
      return sum;
    }

    long sum(long[] arr) {
      long sum = 0;
      for (long item : arr) {
        sum += item;
      }
      return sum;
    }

    long gcd(long a, long b) {
      while (b != 0) {
        long tmp = a % b;
        a = b;
        b = tmp;
      }
      return a;
    }

    private class Scanner {
      private int currentIndex = 0;
      private String[] objects;
      private final BufferedReader myReader;
      private Computable<Character> charComputer;
      private Computable<Double> doubleComputer;
      private Computable<Integer> intComputer;
      private Computable<Long> longComputer;

      Scanner() throws FileNotFoundException {
        InputStream in = DEBUG ? new FileInputStream(FILE_NAME) : System.in;
        myReader = new BufferedReader(new InputStreamReader(in));
        charComputer = () -> objects[currentIndex].charAt(0);
        doubleComputer = () -> Double.parseDouble(objects[currentIndex]);
        intComputer = () -> Integer.parseInt(objects[currentIndex]);
        longComputer = () -> Long.parseLong(objects[currentIndex]);
      }

      String nextLine() throws IOException {
        objects = null;
        currentIndex = 0;
        return myReader.readLine();
      }

      int nextInt() throws IOException {
        return next(intComputer);
      }

      int[] nextIntArray(int n) throws IOException {
        int[] result = new int[n];
        for (int i = 0; i < n; i++) {
          result[i] = nextInt();
        }
        return result;
      }

      long[] nextLongArray(int n) throws IOException {
        long[] result = new long[n];
        for (int i = 0; i < n; i++) {
          result[i] = nextLong();
        }
        return result;
      }

      long nextLong() throws IOException {
        return next(longComputer);
      }

      double nextDouble() throws IOException {
        return next(doubleComputer);

      }

      char nextChar() throws IOException {
        return next(charComputer);
      }

      <T> T next(Computable<T> computer) throws IOException {
        T result;
        if (objects == null || currentIndex >= objects.length) {
          String s = myReader.readLine();
          objects = s.split(" ");
          currentIndex = 0;
        }
        result = computer.compute();
        currentIndex++;
        return result;
      }

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

    }

    interface Computable<T> {
      T compute();
    }

  }

}


import java.io.*;
import java.util.*;

public class DCells {

  private static final String REGEX = " ";
  private static final Boolean DEBUG = false;
  private static final String FILE_NAME = "input.txt";

  public static void main(String[] args) throws IOException {
    if (DEBUG) {
      generate();
    }
    Solver solver = new Solver();
    solver.readData();
    solver.solve();
    solver.print();
  }

  private static void generate() throws IOException {
//    FileWriter writer = new FileWriter("input.txt");
//    writer.close();
  }

  private static class Data {
    int n, m;
    char[][] cell;
  }

  private static class Solver {
    private StringBuilder myStringBuilder = new StringBuilder();
    int t;
    Data[] data;

    void readData() throws IOException {
      Scanner scanner = new Scanner();
      t = scanner.nextInt();
      data = new Data[t];
      for (int i = 0; i < t; i++) {
        Data data = new Data();
        this.data[i] = data;
        data.n = scanner.nextInt();
        data.m = scanner.nextInt();
        data.cell = new char[data.n][data.m];
        for (int x = 0; x < data.n; x++) {
          String line = scanner.nextLine();
          for (int y = 0; y < data.m; y++) {
            data.cell[x][y] = line.charAt(y);
          }
        }
      }
      scanner.close();
    }

    void solve() {
      for (int i = 0; i < t; i++) {
        Data data = this.data[i];
        int goodCount = 0;
        char[][] cell = data.cell;
        int n = data.n;
        int m = data.m;
        for (int x = 0; x < n; x++) {
          for (int y = 0; y < m; y++) {
            if (cell[x][y] == 'G') {
              goodCount++;
            }
            if (cell[x][y] == 'B') {
              if (x > 0 && cell[x - 1][y] == '.') {
                cell[x - 1][y] = '#';
              }
              if (x < n - 1 && cell[x + 1][y] == '.') {
                cell[x + 1][y] = '#';
              }
              if (y > 0 && cell[x][y - 1] == '.') {
                cell[x][y - 1] = '#';
              }

              if (y < m - 1 && cell[x][y + 1] == '.') {
                cell[x][y + 1] = '#';
              }
            }
          }
        }
        if (goodCount == 0) {
          out("Yes");
          newLine();
          continue;
        }
        if (cell[n - 1][m - 1] == '#') {
          out("No");
          newLine();
          continue;
        }

        Deque<Coord> deque = new ArrayDeque<>();
        Set<Coord> visited = new HashSet<>();
        Coord exit = new Coord(n - 1, m - 1);
        deque.push(exit);
        visited.add(exit);
        int freeGoods = 0;
        while (!deque.isEmpty()) {
          Coord next = deque.pop();
          if (cell[next.x][next.y] == '#') {
            continue;
          }
          if (cell[next.x][next.y] == 'G') {
            freeGoods++;
            if (freeGoods == goodCount) {
              out("Yes");
              newLine();
              break;
            }
          }
          List<Coord> neighbours = neighbours(next, n, m);
          for (Coord neighbour : neighbours) {
            if (visited.contains(neighbour)) {
              continue;
            }
            deque.push(neighbour);
            visited.add(neighbour);
          }
        }
        if (freeGoods != goodCount){
          out("No");
          newLine();
        }
      }
    }

    List<Coord> neighbours(Coord coord, int n, int m) {
      ArrayList<Coord> result = new ArrayList<>();
      if (coord.x > 0) {
        result.add(new Coord(coord.x - 1, coord.y));
      }
      if (coord.x < n - 1) {
        result.add(new Coord(coord.x + 1, coord.y));
      }
      if (coord.y > 0) {
        result.add(new Coord(coord.x, coord.y - 1));
      }

      if (coord.y < m - 1) {
        result.add(new Coord(coord.x, coord.y + 1));
      }
      return result;
    }

    static class Coord {
      int x;
      int y;

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

      @Override
      public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Coord pair = (Coord) o;
        return x == pair.x &&
            y == pair.y;
      }

      @Override
      public int hashCode() {
        return Objects.hash(x, y);
      }
    }

    void print() {
      System.out.println(myStringBuilder);
    }

    void out(Object object) {
      myStringBuilder.append(object);
    }

    void out(String string) {
      myStringBuilder.append(string);
    }

    public void out(boolean b) {
      myStringBuilder.append(b);
    }

    public void out(char c) {
      myStringBuilder.append(c);
    }

    public void out(int i) {
      myStringBuilder.append(i);
    }

    public void out(long lng) {
      myStringBuilder.append(lng);
    }

    public void out(float f) {
      myStringBuilder.append(f);
    }

    public void out(double d) {
      myStringBuilder.append(d);
    }

    public void newLine() {
      myStringBuilder.append("\n");
    }

    @SuppressWarnings("SameParameterValue")
    int[] splitInteger(String string, int n) {
      final String[] split = string.split(REGEX, n);
      int[] result = new int[split.length];
      for (int i = 0; i < n; ++i) {
        result[i] = Integer.parseInt(split[i]);
      }
      return result;
    }

    @SuppressWarnings("SameParameterValue")
    long[] splitLong(String string, int n) {
      final String[] split = string.split(REGEX, n);
      long[] result = new long[split.length];
      for (int i = 0; i < n; ++i) {
        result[i] = Long.parseLong(split[i]);
      }
      return result;
    }

    @SuppressWarnings("SameParameterValue")
    double[] splitDouble(String string, int n) {
      final String[] split = string.split(REGEX, n);
      double[] result = new double[split.length];
      for (int i = 0; i < n; ++i) {
        result[i] = Double.parseDouble(split[i]);
      }
      return result;
    }

    @SuppressWarnings("SameParameterValue")
    String[] splitString(String string, int n) {
      return string.split(REGEX, n);
    }

    public int max(int a, int b) {
      return Math.max(a, b);
    }

    public int max(int[] arr) {
      int max = Integer.MIN_VALUE;
      for (int x : arr) {
        max = max(max, x);
      }
      return max;
    }

    public long max(long a, long b) {
      return Math.max(a, b);
    }

    public int min(int a, int b) {
      return Math.min(a, b);
    }

    public long min(long a, long b) {
      return Math.min(a, b);
    }

    public double max(double a, double b) {
      return Math.max(a, b);
    }

    public double min(double a, double b) {
      return Math.min(a, b);
    }

    private final static int MOD = 1000000009;

    int multMod(int a, int b) {
      return ((a % MOD) * (b % MOD)) % MOD;
    }

    int sumMod(int a, int b) {
      return ((a % MOD) + (b % MOD)) % MOD;
    }

    long multMod(long a, long b) {
      return ((a % MOD) * (b % MOD)) % MOD;
    }

    long sumMod(long a, long b) {
      return ((a % MOD) + (b % MOD)) % MOD;
    }

    int sum(int[] arr) {
      int sum = 0;
      for (int item : arr) {
        sum += item;
      }
      return sum;
    }

    long sum(long[] arr) {
      long sum = 0;
      for (long item : arr) {
        sum += item;
      }
      return sum;
    }

    long gcd(long a, long b) {
      while (b != 0) {
        long tmp = a % b;
        a = b;
        b = tmp;
      }
      return a;
    }

    private class Scanner {
      private int currentIndex = 0;
      private String[] objects;
      private final BufferedReader myReader;
      private Computable<Character> charComputer;
      private Computable<Double> doubleComputer;
      private Computable<Integer> intComputer;
      private Computable<Long> longComputer;

      Scanner() throws FileNotFoundException {
        InputStream in = DEBUG ? new FileInputStream(FILE_NAME) : System.in;
        myReader = new BufferedReader(new InputStreamReader(in));
        charComputer = () -> objects[currentIndex].charAt(0);
        doubleComputer = () -> Double.parseDouble(objects[currentIndex]);
        intComputer = () -> Integer.parseInt(objects[currentIndex]);
        longComputer = () -> Long.parseLong(objects[currentIndex]);
      }

      String nextLine() throws IOException {
        objects = null;
        currentIndex = 0;
        return myReader.readLine();
      }

      int nextInt() throws IOException {
        return next(intComputer);
      }

      int[] nextIntArray(int n) throws IOException {
        int[] result = new int[n];
        for (int i = 0; i < n; i++) {
          result[i] = nextInt();
        }
        return result;
      }

      long[] nextLongArray(int n) throws IOException {
        long[] result = new long[n];
        for (int i = 0; i < n; i++) {
          result[i] = nextLong();
        }
        return result;
      }

      long nextLong() throws IOException {
        return next(longComputer);
      }

      double nextDouble() throws IOException {
        return next(doubleComputer);

      }

      char nextChar() throws IOException {
        return next(charComputer);
      }

      <T> T next(Computable<T> computer) throws IOException {
        T result;
        if (objects == null || currentIndex >= objects.length) {
          String s = myReader.readLine();
          objects = s.split(" ");
          currentIndex = 0;
        }
        result = computer.compute();
        currentIndex++;
        return result;
      }

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

    }

    interface Computable<T> {
      T compute();
    }

  }

}


import java.io.*;
import java.util.*;

public class DCells {

  private static final String REGEX = " ";
  private static final Boolean DEBUG = false;
  private static final String FILE_NAME = "input.txt";

  public static void main(String[] args) throws IOException {
    if (DEBUG) {
      generate();
    }
    Solver solver = new Solver();
    solver.readData();
    solver.solve();
    solver.print();
  }

  private static void generate() throws IOException {
//    FileWriter writer = new FileWriter("input.txt");
//    writer.close();
  }

  private static class Data {
    int n, m;
    char[][] cell;
  }

  private static class Solver {
    private StringBuilder myStringBuilder = new StringBuilder();
    int t;
    Data[] data;

    void readData() throws IOException {
      Scanner scanner = new Scanner();
      t = scanner.nextInt();
      data = new Data[t];
      for (int i = 0; i < t; i++) {
        Data data = new Data();
        this.data[i] = data;
        data.n = scanner.nextInt();
        data.m = scanner.nextInt();
        data.cell = new char[data.n][data.m];
        for (int x = 0; x < data.n; x++) {
          String line = scanner.nextLine();
          for (int y = 0; y < data.m; y++) {
            data.cell[x][y] = line.charAt(y);
          }
        }
      }
      scanner.close();
    }

    void solve() {
      for (int i = 0; i < t; i++) {
        Data data = this.data[i];
        int goodCount = 0;
        char[][] cell = data.cell;
        int n = data.n;
        int m = data.m;
        for (int x = 0; x < n; x++) {
          for (int y = 0; y < m; y++) {
            if (cell[x][y] == 'G') {
              goodCount++;
            }
            if (cell[x][y] == 'B') {
              if (x > 0 && cell[x - 1][y] == '.') {
                cell[x - 1][y] = '#';
              }
              if (x < n - 1 && cell[x + 1][y] == '.') {
                cell[x + 1][y] = '#';
              }
              if (y > 0 && cell[x][y - 1] == '.') {
                cell[x][y - 1] = '#';
              }

              if (y < m - 1 && cell[x][y + 1] == '.') {
                cell[x][y + 1] = '#';
              }
            }
          }
        }
        if (goodCount == 0) {
          out("Yes");
          newLine();
          continue;
        }
        if (cell[n - 1][m - 1] == '#' || cell[n - 1][m - 1] == 'B') {
          out("No");
          newLine();
          continue;
        }

        Deque<Coord> deque = new ArrayDeque<>();
        Set<Coord> visited = new HashSet<>();
        Coord exit = new Coord(n - 1, m - 1);
        deque.push(exit);
        visited.add(exit);
        int freeGoods = 0;
        boolean result = false;
        while (!deque.isEmpty()) {
          Coord next = deque.pop();
          if (cell[next.x][next.y] == '#') {
            continue;
          }
          if (cell[next.x][next.y] == 'B') {
            result = false;
            break;
          }
          if (cell[next.x][next.y] == 'G') {
            freeGoods++;
            if (freeGoods == goodCount) {
              result = true;
            }
          }
          List<Coord> neighbours = neighbours(next, n, m);
          for (Coord neighbour : neighbours) {
            if (visited.contains(neighbour)) {
              continue;
            }
            deque.push(neighbour);
            visited.add(neighbour);
          }
        }
        if (result) {
          out("Yes");
        } else {
          out("No");
        }
        newLine();
      }
    }

    List<Coord> neighbours(Coord coord, int n, int m) {
      ArrayList<Coord> result = new ArrayList<>();
      if (coord.x > 0) {
        result.add(new Coord(coord.x - 1, coord.y));
      }
      if (coord.x < n - 1) {
        result.add(new Coord(coord.x + 1, coord.y));
      }
      if (coord.y > 0) {
        result.add(new Coord(coord.x, coord.y - 1));
      }

      if (coord.y < m - 1) {
        result.add(new Coord(coord.x, coord.y + 1));
      }
      return result;
    }

    static class Coord {
      int x;
      int y;

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

      @Override
      public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Coord pair = (Coord) o;
        return x == pair.x &&
            y == pair.y;
      }

      @Override
      public int hashCode() {
        return Objects.hash(x, y);
      }
    }

    void print() {
      System.out.println(myStringBuilder);
    }

    void out(Object object) {
      myStringBuilder.append(object);
    }

    void out(String string) {
      myStringBuilder.append(string);
    }

    public void out(boolean b) {
      myStringBuilder.append(b);
    }

    public void out(char c) {
      myStringBuilder.append(c);
    }

    public void out(int i) {
      myStringBuilder.append(i);
    }

    public void out(long lng) {
      myStringBuilder.append(lng);
    }

    public void out(float f) {
      myStringBuilder.append(f);
    }

    public void out(double d) {
      myStringBuilder.append(d);
    }

    public void newLine() {
      myStringBuilder.append("\n");
    }

    @SuppressWarnings("SameParameterValue")
    int[] splitInteger(String string, int n) {
      final String[] split = string.split(REGEX, n);
      int[] result = new int[split.length];
      for (int i = 0; i < n; ++i) {
        result[i] = Integer.parseInt(split[i]);
      }
      return result;
    }

    @SuppressWarnings("SameParameterValue")
    long[] splitLong(String string, int n) {
      final String[] split = string.split(REGEX, n);
      long[] result = new long[split.length];
      for (int i = 0; i < n; ++i) {
        result[i] = Long.parseLong(split[i]);
      }
      return result;
    }

    @SuppressWarnings("SameParameterValue")
    double[] splitDouble(String string, int n) {
      final String[] split = string.split(REGEX, n);
      double[] result = new double[split.length];
      for (int i = 0; i < n; ++i) {
        result[i] = Double.parseDouble(split[i]);
      }
      return result;
    }

    @SuppressWarnings("SameParameterValue")
    String[] splitString(String string, int n) {
      return string.split(REGEX, n);
    }

    public int max(int a, int b) {
      return Math.max(a, b);
    }

    public int max(int[] arr) {
      int max = Integer.MIN_VALUE;
      for (int x : arr) {
        max = max(max, x);
      }
      return max;
    }

    public long max(long a, long b) {
      return Math.max(a, b);
    }

    public int min(int a, int b) {
      return Math.min(a, b);
    }

    public long min(long a, long b) {
      return Math.min(a, b);
    }

    public double max(double a, double b) {
      return Math.max(a, b);
    }

    public double min(double a, double b) {
      return Math.min(a, b);
    }

    private final static int MOD = 1000000009;

    int multMod(int a, int b) {
      return ((a % MOD) * (b % MOD)) % MOD;
    }

    int sumMod(int a, int b) {
      return ((a % MOD) + (b % MOD)) % MOD;
    }

    long multMod(long a, long b) {
      return ((a % MOD) * (b % MOD)) % MOD;
    }

    long sumMod(long a, long b) {
      return ((a % MOD) + (b % MOD)) % MOD;
    }

    int sum(int[] arr) {
      int sum = 0;
      for (int item : arr) {
        sum += item;
      }
      return sum;
    }

    long sum(long[] arr) {
      long sum = 0;
      for (long item : arr) {
        sum += item;
      }
      return sum;
    }

    long gcd(long a, long b) {
      while (b != 0) {
        long tmp = a % b;
        a = b;
        b = tmp;
      }
      return a;
    }

    private class Scanner {
      private int currentIndex = 0;
      private String[] objects;
      private final BufferedReader myReader;
      private Computable<Character> charComputer;
      private Computable<Double> doubleComputer;
      private Computable<Integer> intComputer;
      private Computable<Long> longComputer;

      Scanner() throws FileNotFoundException {
        InputStream in = DEBUG ? new FileInputStream(FILE_NAME) : System.in;
        myReader = new BufferedReader(new InputStreamReader(in));
        charComputer = () -> objects[currentIndex].charAt(0);
        doubleComputer = () -> Double.parseDouble(objects[currentIndex]);
        intComputer = () -> Integer.parseInt(objects[currentIndex]);
        longComputer = () -> Long.parseLong(objects[currentIndex]);
      }

      String nextLine() throws IOException {
        objects = null;
        currentIndex = 0;
        return myReader.readLine();
      }

      int nextInt() throws IOException {
        return next(intComputer);
      }

      int[] nextIntArray(int n) throws IOException {
        int[] result = new int[n];
        for (int i = 0; i < n; i++) {
          result[i] = nextInt();
        }
        return result;
      }

      long[] nextLongArray(int n) throws IOException {
        long[] result = new long[n];
        for (int i = 0; i < n; i++) {
          result[i] = nextLong();
        }
        return result;
      }

      long nextLong() throws IOException {
        return next(longComputer);
      }

      double nextDouble() throws IOException {
        return next(doubleComputer);

      }

      char nextChar() throws IOException {
        return next(charComputer);
      }

      <T> T next(Computable<T> computer) throws IOException {
        T result;
        if (objects == null || currentIndex >= objects.length) {
          String s = myReader.readLine();
          objects = s.split(" ");
          currentIndex = 0;
        }
        result = computer.compute();
        currentIndex++;
        return result;
      }

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

    }

    interface Computable<T> {
      T compute();
    }

  }

}


// package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class DH4 {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args){
        FastReader scan=new FastReader();
        int t=1;
        t=scan.nextInt();
        while(t-->0){
            int n=scan.nextInt();
            int m=scan.nextInt();
            StringBuilder[] maze=new StringBuilder[n];
            for(int i=0;i<n;i++){
                maze[i]=new StringBuilder(scan.next());
            }
            for(int i=0;i<n;i++){
                for(int j=0;j<m;j++){
                    if(maze[i].charAt(j)=='B'){
                        if(j<m-1&&maze[i].charAt(j+1)=='.'){
                            maze[i].setCharAt(j+1,'#');
                        }if(i<n-1&&maze[i+1].charAt(j)=='.'){
                            maze[i+1].setCharAt(j,'#');
                        }if(j>0&&maze[i].charAt(j-1)=='.'){
                            maze[i].setCharAt(j-1,'#');
                        }if(i>0&&maze[i-1].charAt(j)=='.'){
                            maze[i-1].setCharAt(j,'#');
                        }
                    }
                }
            }
            Set<String> req=new HashSet<>();
            boolean pos=true;
            for(int i=0;i<n;i++){
                for(int j=0;j<m;j++){
                    if(maze[i].charAt(j)=='G'){
                        req.add(i+" "+j);
                    }
                }
            }
            Set<String> vis=new HashSet<>();
            Queue<Pair> q=new LinkedList<>();
            if(maze[n-1].charAt(m-1)!='#'&&maze[n-1].charAt(m-1)!='B'){
                vis.add((n-1)+" "+(m-1));
                req.remove((n-1)+" "+(m-1));
                ((LinkedList<Pair>) q).add(new Pair(n-1,m-1));
            }
            while(!q.isEmpty()){
                Pair cur=q.remove();
                int i=cur.x;
                int j=cur.y;
                String ch=i+" "+j;
                req.remove(ch);
                if(i>0&&maze[i-1].charAt(j)!='#'){
                    if(maze[i-1].charAt(j)=='B'){
                        pos=false;
                    }
                    String add=(i-1)+" "+j;
                    if(!vis.contains(add)){
                        vis.add(add);
                        ((LinkedList<Pair>) q).add(new Pair(i-1,j));
                    }
                }if(j>0&&maze[i].charAt(j-1)!='#'){
                    if(maze[i].charAt(j-1)=='B'){
                        pos=false;
                    }
                    String add=(i)+" "+(j-1);
                    if(!vis.contains(add)){
                        vis.add(add);
                        ((LinkedList<Pair>) q).add(new Pair(i,j-1));
                    }
                }if(i<n-1&&maze[i+1].charAt(j)!='#'){
                    if(maze[i+1].charAt(j)=='B'){
                        pos=false;
                    }
                    String add=(i+1)+" "+j;
                    if(!vis.contains(add)){
                        vis.add(add);
                        ((LinkedList<Pair>) q).add(new Pair(i+1,j));
                    }
                }if(j<m-1&&maze[i].charAt(j+1)!='#'){
                    if(maze[i].charAt(j+1)=='B'){
                        pos=false;
                    }
                    String add=(i)+" "+(j+1);
                    if(!vis.contains(add)){
                        vis.add(add);
                        ((LinkedList<Pair>) q).add(new Pair(i,j+1));
                    }
                }
            }
            if(pos&&req.size()==0&&maze[n-1].charAt(m-1)!='B'){
                out.println("Yes");
            }else{
                out.println("No");
            }
        }
        out.flush();
        out.close();
    }
    static class Pair{
        int x;
        int y;
        Pair(int x,int y){
            this.x=x;
            this.y=y;
        }
    }
    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;
        }
    }

}


// package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class DH4 {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args){
        FastReader scan=new FastReader();
        int t=1;
        t=scan.nextInt();
        while(t-->0){
            int n=scan.nextInt();
            int m=scan.nextInt();
            StringBuilder[] maze=new StringBuilder[n];
            for(int i=0;i<n;i++){
                maze[i]=new StringBuilder(scan.next());
            }
            for(int i=0;i<n;i++){
                for(int j=0;j<m;j++){
                    if(maze[i].charAt(j)=='B'){
                        if(j<m-1&&maze[i].charAt(j+1)=='.'){
                            maze[i].setCharAt(j+1,'#');
                        }if(i<n-1&&maze[i+1].charAt(j)=='.'){
                            maze[i+1].setCharAt(j,'#');
                        }if(j>0&&maze[i].charAt(j-1)=='.'){
                            maze[i].setCharAt(j-1,'#');
                        }if(i>0&&maze[i-1].charAt(j)=='.'){
                            maze[i-1].setCharAt(j,'#');
                        }
                    }
                }
            }
            Set<String> req=new HashSet<>();
            for(int i=0;i<n;i++){
                for(int j=0;j<m;j++){
                    if(maze[i].charAt(j)=='G'){
                        req.add(i+" "+j);
                    }
                }
            }
            Set<String> vis=new HashSet<>();
            Queue<Pair> q=new LinkedList<>();
            if(maze[n-1].charAt(m-1)!='#'&&maze[n-1].charAt(m-1)!='B'){
                vis.add((n-1)+" "+(m-1));
                req.remove((n-1)+" "+(m-1));
                ((LinkedList<Pair>) q).add(new Pair(n-1,m-1));
            }
            while(!q.isEmpty()){
                Pair cur=q.remove();
                int i=cur.x;
                int j=cur.y;
                String ch=i+" "+j;
                req.remove(ch);
                if(i>0&&maze[i-1].charAt(j)!='#'){
                    String add=(i-1)+" "+j;
                    if(!vis.contains(add)){
                        vis.add(add);
                        ((LinkedList<Pair>) q).add(new Pair(i-1,j));
                    }
                }if(j>0&&maze[i].charAt(j-1)!='#'){
                    String add=(i)+" "+(j-1);
                    if(!vis.contains(add)){
                        vis.add(add);
                        ((LinkedList<Pair>) q).add(new Pair(i,j-1));
                    }
                }if(i<n-1&&maze[i+1].charAt(j)!='#'){
                    String add=(i+1)+" "+j;
                    if(!vis.contains(add)){
                        vis.add(add);
                        ((LinkedList<Pair>) q).add(new Pair(i+1,j));
                    }
                }if(j<m-1&&maze[i].charAt(j+1)!='#'){
                    String add=(i)+" "+(j+1);
                    if(!vis.contains(add)){
                        vis.add(add);
                        ((LinkedList<Pair>) q).add(new Pair(i,j+1));
                    }
                }
            }
            if(req.size()==0&&maze[n-1].charAt(m-1)!='B'){
                out.println("Yes");
            }else{
                out.println("No");
            }
        }
        out.flush();
        out.close();
    }
    static class Pair{
        int x;
        int y;
        Pair(int x,int y){
            this.x=x;
            this.y=y;
        }
    }
    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;
        }
    }

}


// package com.company;
import java.util.*;
import java.lang.*;
import java.io.*;
//****Use Integer Wrapper Class for Arrays.sort()****
public class DH4 {
    static PrintWriter out=new PrintWriter(new OutputStreamWriter(System.out));
    public static void main(String[] Args){
        FastReader scan=new FastReader();
        int t=1;
        t=scan.nextInt();
        while(t-->0){
            int n=scan.nextInt();
            int m=scan.nextInt();
            StringBuilder[] maze=new StringBuilder[n];
            for(int i=0;i<n;i++){
                maze[i]=new StringBuilder(scan.next());
            }
            for(int i=0;i<n;i++){
                for(int j=0;j<m;j++){
                    if(maze[i].charAt(j)=='B'){
                        if(j<m-1&&maze[i].charAt(j+1)=='.'){
                            maze[i].setCharAt(j+1,'#');
                        }if(i<n-1&&maze[i+1].charAt(j)=='.'){
                            maze[i+1].setCharAt(j,'#');
                        }if(j>0&&maze[i].charAt(j-1)=='.'){
                            maze[i].setCharAt(j-1,'#');
                        }if(i>0&&maze[i-1].charAt(j)=='.'){
                            maze[i-1].setCharAt(j,'#');
                        }
                    }
                }
            }
            Set<String> req=new HashSet<>();
            for(int i=0;i<n;i++){
                for(int j=0;j<m;j++){
                    if(maze[i].charAt(j)=='G'){
                        req.add(i+" "+j);
                    }
                }
            }
            Set<String> vis=new HashSet<>();
            Queue<Pair> q=new LinkedList<>();
            if(maze[n-1].charAt(m-1)!='#'&&maze[n-1].charAt(m-1)!='B'){
                vis.add((n-1)+" "+(m-1));
                req.remove((n-1)+" "+(m-1));
                ((LinkedList<Pair>) q).add(new Pair(n-1,m-1));
            }
            while(!q.isEmpty()){
                Pair cur=q.remove();
                int i=cur.x;
                int j=cur.y;
                String ch=i+" "+j;
                req.remove(ch);
                if(i>0&&maze[i-1].charAt(j)!='#'){
                    String add=(i-1)+" "+j;
                    if(!vis.contains(add)){
                        vis.add(add);
                        ((LinkedList<Pair>) q).add(new Pair(i-1,j));
                    }
                }if(j>0&&maze[i].charAt(j-1)!='#'){
                    String add=(i)+" "+(j-1);
                    if(!vis.contains(add)){
                        vis.add(add);
                        ((LinkedList<Pair>) q).add(new Pair(i,j-1));
                    }
                }if(i<n-1&&maze[i+1].charAt(j)!='#'){
                    String add=(i+1)+" "+j;
                    if(!vis.contains(add)){
                        vis.add(add);
                        ((LinkedList<Pair>) q).add(new Pair(i+1,j));
                    }
                }if(j<m-1&&maze[i].charAt(j+1)!='#'){
                    String add=(i)+" "+(j+1);
                    if(!vis.contains(add)){
                        vis.add(add);
                        ((LinkedList<Pair>) q).add(new Pair(i,j+1));
                    }
                }
            }
            if(req.size()==0){
                out.println("Yes");
            }else{
                out.println("No");
            }
        }
        out.flush();
        out.close();
    }
    static class Pair{
        int x;
        int y;
        Pair(int x,int y){
            this.x=x;
            this.y=y;
        }
    }
    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;
        }
    }

}


import java.util.*;

public class Main {
    static class Node{
        int x,y;
        public Node(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
    static int[][] dir = {{0,1},{0,-1},{1,0},{-1,0}};
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int t = input.nextInt();
        for (int i=0;i<t;i++){
            int n = input.nextInt();
            int m = input.nextInt(),g = 0;
            boolean flag = true;
            String[] str = new String[n];
            for (int j=0;j<n;j++){
                str[j] = input.next();
                for (int k=0;k<m;k++){
                    if (str[j].charAt(k) == 'G') g++;
                }
            }
            for (int j=0;j<n;j++){
                for (int k=0;k<m;k++){
                    if (str[j].charAt(k) == 'B'){
                        for (int l=0;l<4;l++){
                            int fx = j + dir[l][0];
                            int fy = k + dir[l][1];
                            if (fx<0||fx>=n||fy<0||fy>=m) continue;
                            if (str[fx].charAt(fy) == 'G'){
                                flag = false;
                                break;
                            } else if (str[fx].charAt(fy) == '.'){
                                str[fx] = str[fx].substring(0,fy)+"#"+str[fx].substring(fy+1);
                            }
                        }
                    }
                    if (!flag) break;
                }
                if (!flag) break;
            }
            if (!flag || str[n-1].charAt(m-1) == '#') {
                if (g == 0) System.out.println("Yes");
                else System.out.println("No");
            } else {
                str[n-1] = str[n-1].substring(0,m-1)+"#";
                Queue<Node> queue = new ArrayDeque<>();
                queue.add(new Node(n-1,m-1));
                while (!queue.isEmpty()){
                    Node node = queue.poll();
                    for (int j=0;j<4;j++){
                        int fx = node.x + dir[j][0];
                        int fy = node.y + dir[j][1];
                        if (fx<0||fx>=n||fy<0||fy>=m||str[fx].charAt(fy) == '#') continue;
                        if (str[fx].charAt(fy) == 'G') g--;
                        str[fx] = str[fx].substring(0,fy)+"#"+str[fx].substring(fy+1);
                        queue.add(new Node(fx,fy));
                    }
                }
                if (g == 0) System.out.println("Yes");
                else System.out.println("No");
            }
        }
    }
}


import java.util.*;

public class Main {
    static class Node{
        int x,y;
        public Node(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
    static int[][] dir = {{0,1},{0,-1},{1,0},{-1,0}};
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int t = input.nextInt();
        for (int i=0;i<t;i++){
            int n = input.nextInt();
            int m = input.nextInt(),g = 0;
            boolean flag = true;
            String[] str = new String[n];
            char[][] ch = new char[n][m];
            for (int j=0;j<n;j++){
                str[j] = input.next();
                for (int k=0;k<m;k++){
                    ch[j][k] = str[j].charAt(k);
                    if (str[j].charAt(k) == 'G') g++;
                }
            }
            for (int j=0;j<n;j++){
                for (int k=0;k<m;k++){
                    if (ch[j][k] == 'B'){
                        for (int l=0;l<4;l++){
                            int fx = j + dir[l][0];
                            int fy = k + dir[l][1];
                            if (fx<0||fx>=n||fy<0||fy>=m) continue;
                            if (ch[fx][fy] == 'G'){
                                flag = false;
                                break;
                            } else if (ch[fx][fy] == '.'){
                                ch[fx][fy] = '#';
                            }
                        }
                    }
                    if (!flag) break;
                }
                if (!flag) break;
            }
            if (!flag || ch[n-1][m-1] == '#') {
                if (g == 0) System.out.println("Yes");
                else System.out.println("No");
            } else {
                ch[n-1][m-1] = '#';
                Queue<Node> queue = new ArrayDeque<>();
                queue.add(new Node(n-1,m-1));
                while (!queue.isEmpty()){
                    Node node = queue.poll();
                    for (int j=0;j<4;j++){
                        int fx = node.x + dir[j][0];
                        int fy = node.y + dir[j][1];
                        if (fx<0||fx>=n||fy<0||fy>=m||ch[fx][fy] == '#') continue;
                        if (ch[fx][fy] == 'G') g--;
                        ch[fx][fy] = '#';
                        queue.add(new Node(fx,fy));
                    }
                }
                if (g == 0) System.out.println("Yes");
                else System.out.println("No");
            }
        }
    }
}


import java.util.*;

public class Main {
    static class Node{
        int x,y;
        public Node(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
    static int[][] dir = {{0,1},{0,-1},{1,0},{-1,0}};
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int t = input.nextInt();
        for (int i=0;i<t;i++){
            int n = input.nextInt();
            int m = input.nextInt(),g = 0;
            boolean flag = true;
            String[] str = new String[n];
            for (int j=0;j<n;j++){
                str[j] = input.next();
                for (int k=0;k<m;k++){
                    if (str[j].charAt(k) == 'G') g++;
                }
            }
            for (int j=0;j<n;j++){
                for (int k=0;k<m;k++){
                    if (str[j].charAt(k) == 'B'){
                        for (int l=0;l<4;l++){
                            int fx = j + dir[l][0];
                            int fy = k + dir[l][1];
                            if (fx<0||fx>=n||fy<0||fy>=m) continue;
                            if (str[fx].charAt(fy) == 'G'){
                                flag = false;
                                break;
                            }
                            str[fx] = str[fx].substring(0,fy)+"#"+str[fx].substring(fy+1);
                        }
                    }
                    if (!flag) break;
                }
                if (!flag) break;
            }
            if (!flag || str[n-1].charAt(m-1) == '#') {
                if (g == 0) System.out.println("Yes");
                else System.out.println("No");
            } else {
                str[n-1] = str[n-1].substring(0,m-1)+"#";
                Queue<Node> queue = new ArrayDeque<>();
                queue.add(new Node(n-1,m-1));
                while (!queue.isEmpty()){
                    Node node = queue.poll();
                    for (int j=0;j<4;j++){
                        int fx = node.x + dir[j][0];
                        int fy = node.y + dir[j][1];
                        if (fx<0||fx>=n||fy<0||fy>=m||str[fx].charAt(fy) == '#') continue;
                        if (str[fx].charAt(fy) == 'G') g--;
                        str[fx] = str[fx].substring(0,fy)+"#"+str[fx].substring(fy+1);
                        queue.add(new Node(fx,fy));
                    }
                }
                if (g == 0) System.out.println("Yes");
                else System.out.println("No");
            }
        }
    }
}


import java.util.*;

public class Main {
    static class Node{
        int x,y;
        public Node(int x, int y) {
            this.x = x;
            this.y = y;
        }
    }
    static int[][] dir = {{0,1},{0,-1},{1,0},{-1,0}};
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        int t = input.nextInt();
        for (int i=0;i<t;i++){
            int n = input.nextInt();
            int m = input.nextInt(),g = 0;
            boolean flag = true;
            String[] str = new String[n];
            for (int j=0;j<n;j++){
                str[j] = input.next();
                for (int k=0;k<m;k++){
                    if (str[j].charAt(k) == 'G') g++;
                }
            }
            for (int j=0;j<n;j++){
                for (int k=0;k<m;k++){
                    if (str[j].charAt(k) == 'B'){
                        for (int l=0;l<4;l++){
                            int fx = j + dir[l][0];
                            int fy = k + dir[l][1];
                            if (fx<0||fx>=n||fy<0||fy>=m) continue;
                            if (str[fx].charAt(fy) == 'G'){
                                flag = false;
                                break;
                            }
                            str[fx] = str[fx].substring(0,fy)+"#"+str[fx].substring(fy+1);
                        }
                    }
                    if (!flag) break;
                }
                if (!flag) break;
            }
            if (!flag || str[n-1].charAt(m-1) == '#') {
                if (g == 0) System.out.println("Yes");
                else System.out.println("No");
            } else {
                int[][] vis = new int[n][m];
                Queue<Node> queue = new ArrayDeque<>();
                queue.add(new Node(n-1,m-1));
                while (!queue.isEmpty()){
                    Node node = queue.poll();
                    for (int j=0;j<4;j++){
                        int fx = node.x + dir[j][0];
                        int fy = node.y + dir[j][1];
                        if (fx<0||fx>=n||fy<0||fy>=m||vis[fx][fy]==1) continue;
                        if (str[fx].charAt(fy) == 'G'){
                            g--;
                            str[fx] = str[fx].substring(0,fy)+"#"+str[fx].substring(fy+1);
                        }
                        vis[fx][fy] = 1;
                        queue.add(new Node(fx,fy));
                    }
                }
                if (g == 0) System.out.println("Yes");
                else System.out.println("No");
            }
        }
    }
}


//package CodeForces;

import java.util.Scanner;
import java.util.LinkedList;
import java.util.Queue;

public class SolveTheMaze {

	static class node
	{
		int x;
		int y;
		node(int a,int b)
		{
			this.x=a;
			this.y=b;
		}
	}

	static int solve(char ch[][])
	{
		Queue<node> q=new LinkedList<node>();
		int x=ch.length-1;int y=ch[0].length-1;
		node root=new node(x,y);
		q.add(root);int count=0;
		boolean vis[][]=new boolean[ch.length][ch[0].length];
		vis[ch.length-1][ch[0].length-1]=true;
		while(!q.isEmpty())
		{
			node temp=q.remove();
			if(ch[temp.x][temp.y]=='B')
			{
				return -1;
			}
			if(ch[temp.x][temp.y]=='G')
			{
				count++;
			}
			if(temp.x-1>=0&&ch[temp.x-1][temp.y]!='#'&&ch[temp.x-1][temp.y]!='B'&&!vis[temp.x-1][temp.y])
			{
				node newnode=new node(temp.x-1,temp.y);
				vis[temp.x-1][temp.y]=true;
				q.add(newnode);
			}
			if(temp.y-1>=0&&ch[temp.x][temp.y-1]!='#'&&ch[temp.x][temp.y-1]!='B'&&!vis[temp.x][temp.y-1])
			{
				node newnode=new node(temp.x,temp.y-1);
				vis[temp.x][temp.y-1]=true;
				q.add(newnode);
			}
		}
		return count;
	}

	static int check(char ch[][],int i,int j,boolean vis[][],int dp[][],int n,int m)
	{
		if(i==n&&j==m)
		{
			if(ch[i][j]=='#')
			{
				return -1;
			}
			return 1;
		}
		if(i<0||j<0||i>n||j>m||ch[i][j]=='#')
		{
			return -1;
		}
		if(vis[i][j])
		{
			return -1;
		}
		vis[i][j]=true;
		if(dp[i][j]!=0)
		{
			return dp[i][j];
		}
		int xx[]= {1,0,0,-1};
		int yy[]= {0,1,-1,0};
		dp[i][j]=-1;
		for(int k=0;k<xx.length;k++)
		{
			int ans=check(ch,i+xx[k],j+yy[k],vis,dp,n,m);
			dp[i][j]=Math.max(dp[i][j],ans);
		}
		return dp[i][j];
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int t=s.nextInt();
		while(t>0)
		{
			int n=s.nextInt();
			int m=s.nextInt();
			int g=0;
			char ch[][]=new char[n][m];
			for(int i=0;i<n;i++)
			{
				String str=s.next();
				for(int j=0;j<str.length();j++)
				{
					ch[i][j]=str.charAt(j);
					if(ch[i][j]=='G')
					{
						g++;
					}
				}
			}
			boolean done=true;
			for(int i=0;i<n;i++)
			{
				for(int j=0;j<m;j++)
				{
					if(ch[i][j]=='B')
					{
						if(i-1>=0&&ch[i-1][j]=='G')
						{
							done=false;
							break;
						}
						else if(i-1>=0&&ch[i-1][j]=='.')
						{
							ch[i-1][j]='#';
						}
						if(j-1>=0&&ch[i][j-1]=='G')
						{
							done=false;
							break;
						}
						else if(j-1>=0&&ch[i][j-1]=='.')
						{
							ch[i][j-1]='#';
						}
						if(i+1<n&&ch[i+1][j]=='G')
						{
							done=false;
							break;
						}
						else if(i+1<n&&ch[i+1][j]=='.')
						{
							ch[i+1][j]='#';
						}
						if(j+1<m&&ch[i][j+1]=='G')
						{
							done=false;
							break;
						}
						else if(j+1<m&&ch[i][j+1]=='.')
						{
							ch[i][j+1]='#';
						}
					}
				}
			}

			if(g==0)
			{
				System.out.println("Yes");
			}
			else if(!done)
			{
				System.out.println("No");
			}
			else if(ch[n-1][m-1]!='#')
			{
				int count=solve(ch);
				if(count==g)
				{
					System.out.println("Yes");
				}
				else
				{
					System.out.println("No");
				}
			}
			else
			{
				System.out.println("No");
			}

//			if(done)
//			{
//				int dp[][]=new int[n][m];
//				for(int i=0;i<n;i++)
//				{
//					for(int j=0;j<m;j++)
//					{
//						if(ch[i][j]=='G')
//						{
//							boolean vis[][]=new boolean[n][m];
//							int  check=check(ch,i,j,vis,dp,n-1,m-1);
//							if(check==-1)
//							{
//								done=false;
//								break;
//							}
//						}
//					}
//				}
//
//				if(done)
//				{
//					System.out.println("Yes");
//				}
//				else
//				{
//					System.out.println("No");
//				}
//			}
//			else
//			{
//				System.out.println("No");
//			}
			t--;
		}

	}

}


//package CodeForces;

import java.util.Scanner;

public class SolveTheMaze {

	static int check(char ch[][],int i,int j,boolean vis[][],int dp[][],int n,int m)
	{
		if(i==n&&j==m)
		{
			if(ch[i][j]=='#')
			{
				return -1;
			}
			return 1;
		}
		if(i<0||j<0||i>n||j>m)
		{
			return -1;
		}
		if(vis[i][j])
		{
			return -1;
		}
		vis[i][j]=true;
		if(dp[i][j]!=0)
		{
			return dp[i][j];
		}
		int xx[]= {1,0,0,-1};
		int yy[]= {0,1,-1,0};
		dp[i][j]=-1;
		for(int k=0;k<xx.length;k++)
		{
			int ans=check(ch,i+xx[k],j+yy[k],vis,dp,n,m);
			dp[i][j]=Math.max(dp[i][j],ans);
		}
		return dp[i][j];
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner s=new Scanner(System.in);
		int t=s.nextInt();
		while(t>0)
		{
			int n=s.nextInt();
			int m=s.nextInt();
			char ch[][]=new char[n][m];
			for(int i=0;i<n;i++)
			{
				String str=s.next();
				for(int j=0;j<str.length();j++)
				{
					ch[i][j]=str.charAt(j);
				}
			}
			boolean done=true;
			for(int i=0;i<n;i++)
			{
				for(int j=0;j<m;j++)
				{
					if(ch[i][j]=='B')
					{
						if(i-1>=0&&ch[i-1][j]=='G')
						{
							done=false;
							break;
						}
						else if(i-1>=0)
						{
							ch[i-1][j]='#';
						}
						if(j-1>=0&&ch[i][j-1]=='G')
						{
							done=false;
							break;
						}
						else if(j-1>=0)
						{
							ch[i][j-1]='#';
						}
						if(i+1<n&&ch[i+1][j]=='G')
						{
							done=false;
							break;
						}
						else if(i+1<n)
						{
							ch[i+1][j]='#';
						}
						if(j+1<m&&ch[i][j+1]=='G')
						{
							done=false;
							break;
						}
						else if(j+1<m)
						{
							ch[i][j+1]='#';
						}
					}
				}
			}

			if(done)
			{
				int dp[][]=new int[n][m];
				for(int i=0;i<n;i++)
				{
					for(int j=0;j<m;j++)
					{
						if(ch[i][j]=='G')
						{
							boolean vis[][]=new boolean[n][m];
							int  check=check(ch,i,j,vis,dp,n-1,m-1);
							if(check==-1)
							{
								done=false;
								break;
							}
						}
					}
				}

				if(done)
				{
					System.out.println("Yes");
				}
				else
				{
					System.out.println("No");
				}
			}
			else
			{
				System.out.println("No");
			}
			t--;
		}

	}

}