import java.util.*;
import java.io.*;
public class Main {
    static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            int integer=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    integer*=10;
                    integer+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }
    static int n,m;
    static char arr[][];
    static boolean vis[][];
    public static void main(String args[]) throws IOException {
        Scan input=new Scan();
        int test=input.scanInt();
        for(int t=1;t<=test;t++) {
            n=input.scanInt();
            m=input.scanInt();
            arr=new char[n][m];
            boolean good=false;
            for(int i=0;i<n;i++) {
                String str=input.scanString();
                for(int j=0;j<m;j++) {
                    arr[i][j]=str.charAt(j);
                    if(arr[i][j]=='G') {
                        good=true;
                    }
                }
            }
            if((n==1 && m==1) || !good) {
                System.out.println("YES");
                continue;
            }
            if(n>1 && arr[n-2][m-1]=='B') {
                System.out.println("NO");
                continue;
            }
            if(m>1 && arr[n-1][m-2]=='B') {
                System.out.println("NO");
                continue;
            }
            boolean is_pos=true;
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    if(i>0 && arr[i-1][j]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(i<n-1 && arr[i+1][j]=='G') {
                        is_pos=false;
                        break;
                    }

                    if(j>0 && arr[i][j-1]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(j<m-1 && arr[i][j+1]=='G') {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    if(i>0 && arr[i-1][j]=='.') {
                        arr[i-1][j]='#';
                    }
                    if(i<n-1 && arr[i+1][j]=='.') {
                        arr[i+1][j]='#';
                    }

                    if(j>0 && arr[i][j-1]=='.') {
                        arr[i][j-1]='#';
                    }
                    if(j<m-1 && arr[i][j+1]=='.') {
                        arr[i][j+1]='#';
                    }
                }
            }
            vis=new boolean[n][m];
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='G' || vis[i][j]) {
                        continue;
                    }
                    can_reach(i,j,arr[i][j]);
                    break;
                }
            }
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]=='G' && !vis[i][j]) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            vis=new boolean[n][m];
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B' || vis[i][j]) {
                        continue;
                    }
                    vis=new boolean[n][m];
                    if(can_reach_bad(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }

            System.out.println("YES");
        }
    }
    public static void can_reach(int i,int j, char chr) {
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j]) {
            if(chr==arr[i-1][j] || arr[i-1][j]=='.') {
                can_reach(i-1,j,chr);
            }
        }

        if(i!=n-1 && !vis[i+1][j]) {
            if(chr==arr[i+1][j] || arr[i+1][j]=='.') {
                can_reach(i+1,j,chr);
            }
        }

        if(j!=0 && !vis[i][j-1]) {
            if(chr==arr[i][j-1] || arr[i][j-1]=='.') {
                can_reach(i,j-1,chr);
            }
        }

        if(j!=m-1 && !vis[i][j+1]) {
            if(chr==arr[i][j+1] || arr[i][j+1]=='.') {
                can_reach(i,j+1,chr);
            }
        }
    }

    public static boolean can_reach_bad(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j]) {
            if('B'==arr[i-1][j] || arr[i-1][j]=='G') {
                if(can_reach_bad(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j]) {
            if('B'==arr[i+1][j] || arr[i+1][j]=='G') {
                if(can_reach_bad(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1]) {
            if('B'==arr[i][j-1] || arr[i][j-1]=='G') {
                if(can_reach_bad(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1]) {
            if('B'==arr[i][j+1] || arr[i][j+1]=='G') {
                if(can_reach_bad(i,j+1,chr)) {
                    return true;
                }
            }
        }
        return false;
    }
}


import java.util.*;
import java.io.*;
public class Main {
    static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            int integer=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    integer*=10;
                    integer+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }
    static int n,m;
    static char arr[][];
    static boolean vis[][];
    public static void main(String args[]) throws IOException {
        Scan input=new Scan();
        int test=input.scanInt();
        for(int t=1;t<=test;t++) {
            n=input.scanInt();
            m=input.scanInt();
            arr=new char[n][m];
            boolean good=false;
            for(int i=0;i<n;i++) {
                String str=input.scanString();
                for(int j=0;j<m;j++) {
                    arr[i][j]=str.charAt(j);
                    if(arr[i][j]=='G') {
                        good=true;
                    }
                }
            }
            if((n==1 && m==1) || !good) {
                System.out.println("YES");
                continue;
            }
            if(n>1 && arr[n-2][m-1]=='B') {
                System.out.println("NO");
                continue;
            }
            if(m>1 && arr[n-1][m-2]=='B') {
                System.out.println("NO");
                continue;
            }
            boolean is_pos=true;
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='G') {
                        continue;
                    }
                    vis=new boolean[n][m];
                    if(!can_reach(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }

            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    vis=new boolean[n][m];
                    if(can_reach_bad(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    if(i>0 && arr[i-1][j]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(i<n-1 && arr[i+1][j]=='G') {
                        is_pos=false;
                        break;
                    }

                    if(j>0 && arr[i][j-1]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(j<m-1 && arr[i][j+1]=='G') {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            System.out.println("YES");
        }
    }
    public static boolean can_reach(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j] && arr[i-1][j]!='#') {
            if(chr==arr[i-1][j] || arr[i-1][j]=='.') {
                if(can_reach(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j]&& arr[i+1][j]!='#') {
            if(chr==arr[i+1][j] || arr[i+1][j]=='.') {
                if(can_reach(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1] && arr[i][j-1]!='#') {
            if(chr==arr[i][j-1] || arr[i][j-1]=='.') {
                if(can_reach(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1] && arr[i][j+1]!='#') {
            if(chr==arr[i][j+1] || arr[i][j+1]=='.') {
                if(can_reach(i,j+1,chr)) {
                    return true;
                }
            }
        }
        vis[i][j]=false;
        return false;
    }

    public static boolean can_reach_bad(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j] && arr[i-1][j]!='#') {
            if('B'==arr[i-1][j] || arr[i-1][j]=='G') {
                if(can_reach_bad(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j] && arr[i+1][j]!='#') {
            if('B'==arr[i+1][j] || arr[i+1][j]=='G') {
                if(can_reach_bad(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1] && arr[i][j-1]!='#') {
            if('B'==arr[i][j-1] || arr[i][j-1]=='G') {
                if(can_reach_bad(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1] && arr[i][j+1]!='#') {
            if('B'==arr[i][j+1] || arr[i][j+1]=='G') {
                if(can_reach_bad(i,j+1,chr)) {
                    return true;
                }
            }
        }
        vis[i][j]=false;
        return false;
    }
}


import java.util.*;
import java.io.*;
public class Main {
    static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            int integer=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    integer*=10;
                    integer+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }
    static int n,m;
    static char arr[][];
    static boolean vis[][];
    public static void main(String args[]) throws IOException {
        Scan input=new Scan();
        int test=input.scanInt();
        for(int t=1;t<=test;t++) {
            n=input.scanInt();
            m=input.scanInt();
            arr=new char[n][m];
            boolean good=false;
            for(int i=0;i<n;i++) {
                String str=input.scanString();
                for(int j=0;j<m;j++) {
                    arr[i][j]=str.charAt(j);
                    if(arr[i][j]=='G') {
                        good=true;
                    }
                }
            }
            if((n==1 && m==1) || !good) {
                System.out.println("YES");
                continue;
            }
            if(n>1 && arr[n-2][m-1]=='B') {
                System.out.println("NO");
                continue;
            }
            if(m>1 && arr[n-1][m-2]=='B') {
                System.out.println("NO");
                continue;
            }
            boolean is_pos=true;
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='G') {
                        continue;
                    }
                    vis=new boolean[n][m];
                    if(!can_reach(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }

            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    vis=new boolean[n][m];
                    if(can_reach_bad(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    if(i>0 && arr[i-1][j]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(i<n-1 && arr[i+1][j]=='G') {
                        is_pos=false;
                        break;
                    }

                    if(j>0 && arr[i][j-1]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(j<m-1 && arr[i][j+1]=='G') {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            System.out.println("YES");
        }
    }
    public static boolean can_reach(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j] && arr[i-1][j]!='#') {
            if(chr==arr[i-1][j] || arr[i-1][j]=='.') {
                if(can_reach(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j]&& arr[i+1][j]!='#') {
            if(chr==arr[i+1][j] || arr[i+1][j]=='.') {
                if(can_reach(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1] && arr[i][j-1]!='#') {
            if(chr==arr[i][j-1] || arr[i][j-1]=='.') {
                if(can_reach(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1] && arr[i][j+1]!='#') {
            if(chr==arr[i][j+1] || arr[i][j+1]=='.') {
                if(can_reach(i,j+1,chr)) {
                    return true;
                }
            }
        }
        return false;
    }

    public static boolean can_reach_bad(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j] && arr[i-1][j]!='#') {
            if('B'==arr[i-1][j] || arr[i-1][j]=='G') {
                if(can_reach_bad(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j] && arr[i+1][j]!='#') {
            if('B'==arr[i+1][j] || arr[i+1][j]=='G') {
                if(can_reach_bad(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1] && arr[i][j-1]!='#') {
            if('B'==arr[i][j-1] || arr[i][j-1]=='G') {
                if(can_reach_bad(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1] && arr[i][j+1]!='#') {
            if('B'==arr[i][j+1] || arr[i][j+1]=='G') {
                if(can_reach_bad(i,j+1,chr)) {
                    return true;
                }
            }
        }
        return false;
    }
}


import java.util.*;
import java.io.*;
public class Main {
    static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            int integer=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    integer*=10;
                    integer+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }
    static int n,m;
    static char arr[][];
    static boolean vis[][];
    public static void main(String args[]) throws IOException {
        Scan input=new Scan();
        int test=input.scanInt();
        for(int t=1;t<=test;t++) {
            n=input.scanInt();
            m=input.scanInt();
            arr=new char[n][m];
            boolean good=false;
            for(int i=0;i<n;i++) {
                String str=input.scanString();
                for(int j=0;j<m;j++) {
                    arr[i][j]=str.charAt(j);
                    if(arr[i][j]=='G') {
                        good=true;
                    }
                }
            }
            if((n==1 && m==1) || !good) {
                System.out.println("YES");
                continue;
            }
            if(n>1 && arr[n-2][m-1]=='B') {
                System.out.println("NO");
                continue;
            }
            if(m>1 && arr[n-1][m-2]=='B') {
                System.out.println("NO");
                continue;
            }
            boolean is_pos=true;
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    if(i>0 && arr[i-1][j]=='.') {
                        arr[i-1][j]='#';
                    }
                    if(i<n-1 && arr[i+1][j]=='.') {
                        arr[i+1][j]='#';
                    }

                    if(j>0 && arr[i][j-1]=='.') {
                        arr[i][j-1]='#';
                    }
                    if(j<m-1 && arr[i][j+1]=='.') {
                        arr[i][j+1]='#';
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='G') {
                        continue;
                    }
                    vis=new boolean[n][m];
                    if(!can_reach(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }

            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    vis=new boolean[n][m];
                    if(can_reach_bad(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    if(i>0 && arr[i-1][j]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(i<n-1 && arr[i+1][j]=='G') {
                        is_pos=false;
                        break;
                    }

                    if(j>0 && arr[i][j-1]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(j<m-1 && arr[i][j+1]=='G') {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }

            System.out.println("YES");
        }
    }
    public static boolean can_reach(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j] && arr[i-1][j]!='#') {
            if(chr==arr[i-1][j] || arr[i-1][j]=='.') {
                if(can_reach(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j]&& arr[i+1][j]!='#') {
            if(chr==arr[i+1][j] || arr[i+1][j]=='.') {
                if(can_reach(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1] && arr[i][j-1]!='#') {
            if(chr==arr[i][j-1] || arr[i][j-1]=='.') {
                if(can_reach(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1] && arr[i][j+1]!='#') {
            if(chr==arr[i][j+1] || arr[i][j+1]=='.') {
                if(can_reach(i,j+1,chr)) {
                    return true;
                }
            }
        }
        vis[i][j]=false;
        return false;
    }

    public static boolean can_reach_bad(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j] && arr[i-1][j]!='#') {
            if('B'==arr[i-1][j] || arr[i-1][j]=='G') {
                if(can_reach_bad(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j] && arr[i+1][j]!='#') {
            if('B'==arr[i+1][j] || arr[i+1][j]=='G') {
                if(can_reach_bad(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1] && arr[i][j-1]!='#') {
            if('B'==arr[i][j-1] || arr[i][j-1]=='G') {
                if(can_reach_bad(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1] && arr[i][j+1]!='#') {
            if('B'==arr[i][j+1] || arr[i][j+1]=='G') {
                if(can_reach_bad(i,j+1,chr)) {
                    return true;
                }
            }
        }
        vis[i][j]=false;
        return false;
    }
}


import java.util.*;
import java.io.*;
public class Main {
    static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            int integer=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    integer*=10;
                    integer+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }
    static int n,m;
    static char arr[][];
    static boolean vis[][];
    public static void main(String args[]) throws IOException {
        Scan input=new Scan();
        int test=input.scanInt();
        for(int t=1;t<=test;t++) {
            n=input.scanInt();
            m=input.scanInt();
            arr=new char[n][m];
            boolean good=false;
            for(int i=0;i<n;i++) {
                String str=input.scanString();
                for(int j=0;j<m;j++) {
                    arr[i][j]=str.charAt(j);
                    if(arr[i][j]=='G') {
                        good=true;
                    }
                }
            }
            if((n==1 && m==1) || !good) {
                System.out.println("YES");
                continue;
            }
            if(n>1 && arr[n-2][m-1]=='B') {
                System.out.println("NO");
                continue;
            }
            if(m>1 && arr[n-1][m-2]=='B') {
                System.out.println("NO");
                continue;
            }
            boolean is_pos=true;
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    if(i>0 && arr[i-1][j]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(i<n-1 && arr[i+1][j]=='G') {
                        is_pos=false;
                        break;
                    }

                    if(j>0 && arr[i][j-1]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(j<m-1 && arr[i][j+1]=='G') {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    if(i>0 && arr[i-1][j]=='.') {
                        arr[i-1][j]='#';
                    }
                    if(i<n-1 && arr[i+1][j]=='.') {
                        arr[i+1][j]='#';
                    }

                    if(j>0 && arr[i][j-1]=='.') {
                        arr[i][j-1]='#';
                    }
                    if(j<m-1 && arr[i][j+1]=='.') {
                        arr[i][j+1]='#';
                    }
                }
            }
            boolean done=false;
            vis=new boolean[n][m];
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='G') {
                        continue;
                    }
                    can_reach(i,j,arr[i][j]);
                    done=true;
                    break;
                }
                if(done) {
                    break;
                }
            }
//            for(int i=0;i<n;i++) {
//                for(int j=0;j<m;j++) {
//                    System.out.print(vis[i][j]?1:0);
//                    System.out.print(" ");
//                }
//                System.out.println();
//            }
            if(!vis[n-1][m-1]) {
                System.out.println("NO");
                continue;
            }
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]=='G' && !vis[i][j]) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            vis=new boolean[n][m];
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B' || vis[i][j]) {
                        continue;
                    }
                    vis=new boolean[n][m];
                    if(can_reach_bad(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }

            System.out.println("YES");
        }
    }
    public static void can_reach(int i,int j, char chr) {
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j]) {
            if('G'==arr[i-1][j] || arr[i-1][j]=='.') {
                can_reach(i-1,j,chr);
            }
        }

        if(i!=n-1 && !vis[i+1][j]) {
            if('G'==arr[i+1][j] || arr[i+1][j]=='.') {
                can_reach(i+1,j,chr);
            }
        }

        if(j!=0 && !vis[i][j-1]) {
            if('G'==arr[i][j-1] || arr[i][j-1]=='.') {
                can_reach(i,j-1,chr);
            }
        }

        if(j!=m-1 && !vis[i][j+1]) {
            if('G'==arr[i][j+1] || arr[i][j+1]=='.') {
                can_reach(i,j+1,chr);
            }
        }
    }

    public static boolean can_reach_bad(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j]) {
            if('B'==arr[i-1][j] || arr[i-1][j]=='G') {
                if(can_reach_bad(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j]) {
            if('B'==arr[i+1][j] || arr[i+1][j]=='G') {
                if(can_reach_bad(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1]) {
            if('B'==arr[i][j-1] || arr[i][j-1]=='G') {
                if(can_reach_bad(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1]) {
            if('B'==arr[i][j+1] || arr[i][j+1]=='G') {
                if(can_reach_bad(i,j+1,chr)) {
                    return true;
                }
            }
        }
        return false;
    }
}


import java.util.*;
import java.io.*;
public class Main {
    static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            int integer=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    integer*=10;
                    integer+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }
    static int n,m;
    static char arr[][];
    static boolean vis[][];
    public static void main(String args[]) throws IOException {
        Scan input=new Scan();
        int test=input.scanInt();
        for(int t=1;t<=test;t++) {
            n=input.scanInt();
            m=input.scanInt();
            arr=new char[n][m];
            boolean good=false;
            for(int i=0;i<n;i++) {
                String str=input.scanString();
                for(int j=0;j<m;j++) {
                    arr[i][j]=str.charAt(j);
                    if(arr[i][j]=='G') {
                        good=true;
                    }
                }
            }
            if((n==1 && m==1) || !good) {
                System.out.println("YES");
                continue;
            }
            if(n>1 && arr[n-2][m-1]=='B') {
                System.out.println("NO");
                continue;
            }
            if(m>1 && arr[n-1][m-2]=='B') {
                System.out.println("NO");
                continue;
            }
            boolean is_pos=true;
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    if(i>0 && arr[i-1][j]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(i<n-1 && arr[i+1][j]=='G') {
                        is_pos=false;
                        break;
                    }

                    if(j>0 && arr[i][j-1]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(j<m-1 && arr[i][j+1]=='G') {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    if(i>0 && arr[i-1][j]=='.') {
                        arr[i-1][j]='#';
                    }
                    if(i<n-1 && arr[i+1][j]=='.') {
                        arr[i+1][j]='#';
                    }

                    if(j>0 && arr[i][j-1]=='.') {
                        arr[i][j-1]='#';
                    }
                    if(j<m-1 && arr[i][j+1]=='.') {
                        arr[i][j+1]='#';
                    }
                }
            }
            vis=new boolean[n][m];
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='G' || vis[i][j]) {
                        continue;
                    }
                    can_reach(i,j,arr[i][j]);
                    break;
                }
            }
            if(!vis[n-1][m-1]) {
                System.out.println("NO");
                continue;
            }
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]=='G' && !vis[i][j]) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            vis=new boolean[n][m];
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B' || vis[i][j]) {
                        continue;
                    }
                    vis=new boolean[n][m];
                    if(can_reach_bad(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }

            System.out.println("YES");
        }
    }
    public static void can_reach(int i,int j, char chr) {
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j]) {
            if(chr==arr[i-1][j] || arr[i-1][j]=='.') {
                can_reach(i-1,j,chr);
            }
        }

        if(i!=n-1 && !vis[i+1][j]) {
            if(chr==arr[i+1][j] || arr[i+1][j]=='.') {
                can_reach(i+1,j,chr);
            }
        }

        if(j!=0 && !vis[i][j-1]) {
            if(chr==arr[i][j-1] || arr[i][j-1]=='.') {
                can_reach(i,j-1,chr);
            }
        }

        if(j!=m-1 && !vis[i][j+1]) {
            if(chr==arr[i][j+1] || arr[i][j+1]=='.') {
                can_reach(i,j+1,chr);
            }
        }
    }

    public static boolean can_reach_bad(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j]) {
            if('B'==arr[i-1][j] || arr[i-1][j]=='G') {
                if(can_reach_bad(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j]) {
            if('B'==arr[i+1][j] || arr[i+1][j]=='G') {
                if(can_reach_bad(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1]) {
            if('B'==arr[i][j-1] || arr[i][j-1]=='G') {
                if(can_reach_bad(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1]) {
            if('B'==arr[i][j+1] || arr[i][j+1]=='G') {
                if(can_reach_bad(i,j+1,chr)) {
                    return true;
                }
            }
        }
        return false;
    }
}


import java.util.*;
import java.io.*;
public class Main {
    static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            int integer=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    integer*=10;
                    integer+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }
    static int n,m;
    static char arr[][];
    static boolean vis[][];
    public static void main(String args[]) throws IOException {
        Scan input=new Scan();
        int test=input.scanInt();
        for(int t=1;t<=test;t++) {
            n=input.scanInt();
            m=input.scanInt();
            arr=new char[n][m];
            boolean good=false;
            for(int i=0;i<n;i++) {
                String str=input.scanString();
                for(int j=0;j<m;j++) {
                    arr[i][j]=str.charAt(j);
                    if(arr[i][j]=='G') {
                        good=true;
                    }
                }
            }
            if((n==1 && m==1) || !good) {
                System.out.println("YES");
                continue;
            }
            if(n>1 && arr[n-2][m-1]=='B') {
                System.out.println("NO");
                continue;
            }
            if(m>1 && arr[n-1][m-2]=='B') {
                System.out.println("NO");
                continue;
            }
            boolean is_pos=true;
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    if(i>0 && arr[i-1][j]=='.') {
                        arr[i-1][j]='#';
                    }
                    if(i<n-1 && arr[i+1][j]=='.') {
                        arr[i+1][j]='#';
                    }

                    if(j>0 && arr[i][j-1]=='.') {
                        arr[i][j-1]='#';
                    }
                    if(j<m-1 && arr[i][j+1]=='.') {
                        arr[i][j+1]='#';
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='G') {
                        continue;
                    }
                    vis=new boolean[n][m];
                    if(!can_reach(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }

            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    vis=new boolean[n][m];
                    if(can_reach_bad(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    if(i>0 && arr[i-1][j]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(i<n-1 && arr[i+1][j]=='G') {
                        is_pos=false;
                        break;
                    }

                    if(j>0 && arr[i][j-1]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(j<m-1 && arr[i][j+1]=='G') {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }

            System.out.println("YES");
        }
    }
    public static boolean can_reach(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j] && arr[i-1][j]!='#') {
            if(chr==arr[i-1][j] || arr[i-1][j]=='.') {
                if(can_reach(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j]&& arr[i+1][j]!='#') {
            if(chr==arr[i+1][j] || arr[i+1][j]=='.') {
                if(can_reach(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1] && arr[i][j-1]!='#') {
            if(chr==arr[i][j-1] || arr[i][j-1]=='.') {
                if(can_reach(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1] && arr[i][j+1]!='#') {
            if(chr==arr[i][j+1] || arr[i][j+1]=='.') {
                if(can_reach(i,j+1,chr)) {
                    return true;
                }
            }
        }
//        vis[i][j]=false;
        return false;
    }

    public static boolean can_reach_bad(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j] && arr[i-1][j]!='#') {
            if('B'==arr[i-1][j] || arr[i-1][j]=='G') {
                if(can_reach_bad(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j] && arr[i+1][j]!='#') {
            if('B'==arr[i+1][j] || arr[i+1][j]=='G') {
                if(can_reach_bad(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1] && arr[i][j-1]!='#') {
            if('B'==arr[i][j-1] || arr[i][j-1]=='G') {
                if(can_reach_bad(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1] && arr[i][j+1]!='#') {
            if('B'==arr[i][j+1] || arr[i][j+1]=='G') {
                if(can_reach_bad(i,j+1,chr)) {
                    return true;
                }
            }
        }
//        vis[i][j]=false;
        return false;
    }
}


import java.util.*;
import java.io.*;
public class Main {
    static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            int integer=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    integer*=10;
                    integer+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }
    static int n,m;
    static char arr[][];
    static boolean vis[][];
    public static void main(String args[]) throws IOException {
        Scan input=new Scan();
        int test=input.scanInt();
        for(int t=1;t<=test;t++) {
            n=input.scanInt();
            m=input.scanInt();
            arr=new char[n][m];
            boolean good=false;
            for(int i=0;i<n;i++) {
                String str=input.scanString();
                for(int j=0;j<m;j++) {
                    arr[i][j]=str.charAt(j);
                    if(arr[i][j]=='G') {
                        good=true;
                    }
                }
            }
            if((n==1 && m==1) || !good) {
                System.out.println("YES");
                continue;
            }
            if(n>1 && arr[n-2][m-1]=='B') {
                System.out.println("NO");
                continue;
            }
            if(m>1 && arr[n-1][m-2]=='B') {
                System.out.println("NO");
                continue;
            }
            boolean is_pos=true;
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='G') {
                        continue;
                    }
                    vis=new boolean[n][m];
                    if(!can_reach(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }

            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    vis=new boolean[n][m];
                    if(can_reach_bad(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    if(i>0 && arr[i-1][j]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(i<n-1 && arr[i+1][j]=='G') {
                        is_pos=false;
                        break;
                    }

                    if(j>0 && arr[i][j-1]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(i<m-1 && arr[i][j+1]=='G') {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            System.out.println("YES");
        }
    }
    public static boolean can_reach(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j]) {
            if(chr==arr[i-1][j] || arr[i-1][j]=='.') {
                if(can_reach(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j]) {
            if(chr==arr[i+1][j] || arr[i+1][j]=='.') {
                if(can_reach(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1]) {
            if(chr==arr[i][j-1] || arr[i][j-1]=='.') {
                if(can_reach(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1]) {
            if(chr==arr[i][j+1] || arr[i][j+1]=='.') {
                if(can_reach(i,j+1,chr)) {
                    return true;
                }
            }
        }
        return false;
    }

    public static boolean can_reach_bad(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j]) {
            if('B'==arr[i-1][j] || arr[i-1][j]=='G') {
                if(can_reach_bad(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j]) {
            if('B'==arr[i+1][j] || arr[i+1][j]=='G') {
                if(can_reach_bad(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1]) {
            if('B'==arr[i][j-1] || arr[i][j-1]=='G') {
                if(can_reach_bad(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1]) {
            if('B'==arr[i][j+1] || arr[i][j+1]=='G') {
                if(can_reach_bad(i,j+1,chr)) {
                    return true;
                }
            }
        }
        return false;
    }
}


import java.util.*;
import java.io.*;
public class Main {
    static class Scan {
        private byte[] buf=new byte[1024];
        private int index;
        private InputStream in;
        private int total;
        public Scan()
        {
            in=System.in;
        }
        public int scan()throws IOException
        {
            if(total<0)
            throw new InputMismatchException();
            if(index>=total)
            {
                index=0;
                total=in.read(buf);
                if(total<=0)
                return -1;
            }
            return buf[index++];
        }
        public int scanInt()throws IOException
        {
            int integer=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n))
            {
                if(n>='0'&&n<='9')
                {
                    integer*=10;
                    integer+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            return neg*integer;
        }
        public double scanDouble()throws IOException
        {
            double doub=0;
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            int neg=1;
            if(n=='-')
            {
                neg=-1;
                n=scan();
            }
            while(!isWhiteSpace(n)&&n!='.')
            {
                if(n>='0'&&n<='9')
                {
                    doub*=10;
                    doub+=n-'0';
                    n=scan();
                }
                else throw new InputMismatchException();
            }
            if(n=='.')
            {
                n=scan();
                double temp=1;
                while(!isWhiteSpace(n))
                {
                    if(n>='0'&&n<='9')
                    {
                        temp/=10;
                        doub+=(n-'0')*temp;
                        n=scan();
                    }
                    else throw new InputMismatchException();
                }
            }
            return doub*neg;
        }
        public String scanString()throws IOException
        {
            StringBuilder sb=new StringBuilder();
            int n=scan();
            while(isWhiteSpace(n))
            n=scan();
            while(!isWhiteSpace(n))
            {
                sb.append((char)n);
                n=scan();
            }
            return sb.toString();
        }
        private boolean isWhiteSpace(int n)
        {
            if(n==' '||n=='\n'||n=='\r'||n=='\t'||n==-1)
            return true;
            return false;
        }
    }
    static int n,m;
    static char arr[][];
    static boolean vis[][];
    public static void main(String args[]) throws IOException {
        Scan input=new Scan();
        int test=input.scanInt();
        for(int t=1;t<=test;t++) {
            n=input.scanInt();
            m=input.scanInt();
            arr=new char[n][m];
            boolean good=false;
            for(int i=0;i<n;i++) {
                String str=input.scanString();
                for(int j=0;j<m;j++) {
                    arr[i][j]=str.charAt(j);
                    if(arr[i][j]=='G') {
                        good=true;
                    }
                }
            }
            if((n==1 && m==1) || !good) {
                System.out.println("YES");
                continue;
            }
            if(n>1 && arr[n-2][m-1]=='B') {
                System.out.println("NO");
                continue;
            }
            if(m>1 && arr[n-1][m-2]=='B') {
                System.out.println("NO");
                continue;
            }
            boolean is_pos=true;
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    if(i>0 && arr[i-1][j]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(i<n-1 && arr[i+1][j]=='G') {
                        is_pos=false;
                        break;
                    }

                    if(j>0 && arr[i][j-1]=='G') {
                        is_pos=false;
                        break;
                    }
                    if(j<m-1 && arr[i][j+1]=='G') {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B') {
                        continue;
                    }
                    if(i>0 && arr[i-1][j]=='.') {
                        arr[i-1][j]='#';
                    }
                    if(i<n-1 && arr[i+1][j]=='.') {
                        arr[i+1][j]='#';
                    }

                    if(j>0 && arr[i][j-1]=='.') {
                        arr[i][j-1]='#';
                    }
                    if(j<m-1 && arr[i][j+1]=='.') {
                        arr[i][j+1]='#';
                    }
                }
            }
            vis=new boolean[n][m];
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='G' || vis[i][j]) {
                        continue;
                    }
                    if(!can_reach(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }
            vis=new boolean[n][m];
            for(int i=0;i<n;i++) {
                for(int j=0;j<m;j++) {
                    if(arr[i][j]!='B' || vis[i][j]) {
                        continue;
                    }
                    vis=new boolean[n][m];
                    if(can_reach_bad(i,j,arr[i][j])) {
                        is_pos=false;
                        break;
                    }
                }
                if(!is_pos) {
                    break;
                }
            }
            if(!is_pos) {
                System.out.println("NO");
                continue;
            }

            System.out.println("YES");
        }
    }
    public static boolean can_reach(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j]) {
            if(chr==arr[i-1][j] || arr[i-1][j]=='.') {
                if(can_reach(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j]) {
            if(chr==arr[i+1][j] || arr[i+1][j]=='.') {
                if(can_reach(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1]) {
            if(chr==arr[i][j-1] || arr[i][j-1]=='.') {
                if(can_reach(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1]) {
            if(chr==arr[i][j+1] || arr[i][j+1]=='.') {
                if(can_reach(i,j+1,chr)) {
                    return true;
                }
            }
        }
        return false;
    }

    public static boolean can_reach_bad(int i,int j, char chr) {
        if(i==n-1 && j==m-1) {
            return true;
        }
        vis[i][j]=true;
        if(i!=0 && !vis[i-1][j]) {
            if('B'==arr[i-1][j] || arr[i-1][j]=='G') {
                if(can_reach_bad(i-1,j,chr)) {
                    return true;
                }
            }
        }

        if(i!=n-1 && !vis[i+1][j]) {
            if('B'==arr[i+1][j] || arr[i+1][j]=='G') {
                if(can_reach_bad(i+1,j,chr)) {
                    return true;
                }
            }
        }

        if(j!=0 && !vis[i][j-1]) {
            if('B'==arr[i][j-1] || arr[i][j-1]=='G') {
                if(can_reach_bad(i,j-1,chr)) {
                    return true;
                }
            }
        }

        if(j!=m-1 && !vis[i][j+1]) {
            if('B'==arr[i][j+1] || arr[i][j+1]=='G') {
                if(can_reach_bad(i,j+1,chr)) {
                    return true;
                }
            }
        }
        return false;
    }
}


import com.sun.deploy.uitoolkit.Window;
import sun.awt.image.ImageWatched;

import java.io.*;
import java.util.*;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.stream.IntStream;

public class Main {
    public static void main(String[] args){
        InputStream  inputstream;
        OutputStream outputstream;
        inputstream = System.in;
        outputstream = System.out;
        InputReader in = new InputReader(inputstream);
        PrintWriter out = new PrintWriter(outputstream);
        int t = in.nextInt();
        while(t-- > 0) {
            Task solver = new Task();
            solver.solve(in, out);
        }
        out.close();
    }

    static class Task{

        private static final int tx[] = {1,-1,0,0};
        private static final int ty[] = {0,0,1,-1};
        int n,m;
        Character[][] a;

        boolean inBoard(int u,int v){
            return (0 <= u && u < n && 0 <= v && v < m);
        }

        public void solve(InputReader in,PrintWriter out){
            n = in.nextInt();
            m = in.nextInt();
            a = new Character[n][m];
            for(int i = 0;i < n;++i){
                String s = in.nextLine();
                for(int j = 0;j < s.length();++j){
                    a[i][j] = s.charAt(j);
                }
            }
            for(int i = 0;i < n;++i){
                for(int j = 0;j < m;++j){
                    for(int k = 0;k < 4;++k){
                        int u = i + tx[k];
                        int v = j + ty[k];
                        if(inBoard(u,v) && a[i][j] == 'B' && a[u][v] == '.'){
                            a[u][v] = '#';
                        }
                    }
                }
            }
            boolean chk = bfs();
            out.print(chk ? "Yes\n" : "No\n");
        }

        boolean bfs(){
            boolean[][] vis = new boolean[n][m];
            Queue < Pair > que = new LinkedList<>();
            que.offer(new Pair(n - 1,m - 1));
            vis[n - 1][m - 1] = true;
            while(!que.isEmpty()){
                Pair top = que.poll();
                int u = top.u;
                int v = top.v;
                for(int k = 0;k < 4;++k){
                    int nxt_u = u + tx[k];
                    int nxt_v = v + ty[k];
                    if(inBoard(nxt_u,nxt_v)){
                        if(a[nxt_u][nxt_v] != '#' && !vis[nxt_u][nxt_v]){
                            vis[nxt_u][nxt_v] = true;
                            que.offer(new Pair(nxt_u,nxt_v));
                        }
                    }
                }
            }
            int good = 0,bad = 0,cgood = 0;
            for(int i = 0;i < n;++i){
                for(int j = 0;j < m;++j){
                    good += (a[i][j] == 'G' && vis[i][j] ? 1 : 0);
                    cgood += (a[i][j] == 'G' ? 1 : 0);
                    bad += (a[i][j] == 'B' && vis[i][j] ? 1 : 0);
                }
            }
            if(cgood == 0){
                return true;
            }
            return (a[n - 1][m - 1] != '#' && good == cgood && bad == 0);
        }

        private class Pair {
            public int u,v;
            Pair(int u,int v){
                this.u = u;
                this.v = v;
            }
        }
    }

    static class InputReader{
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream){
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next(){
            while(tokenizer == null || !tokenizer.hasMoreTokens()){
                try{
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e){
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

        public String nextLine(){
            String ret_str = "";
            try {
                ret_str = reader.readLine();
            } catch (IOException e){
                e.printStackTrace();
            }
            return ret_str;
        }
    }
}


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

public class Main {
    public static void main(String[] args){
        InputStream  inputstream;
        OutputStream outputstream;
        inputstream = System.in;
        outputstream = System.out;
        InputReader in = new InputReader(inputstream);
        PrintWriter out = new PrintWriter(outputstream);
        int t = in.nextInt();
        while(t-- > 0) {
            Task solver = new Task();
            solver.solve(in, out);
        }
        out.close();
    }

    static class Task{

        private static final int tx[] = {1,-1,0,0};
        private static final int ty[] = {0,0,1,-1};
        int n,m;
        Character[][] a;

        boolean inBoard(int u,int v){
            return (0 <= u && u < n && 0 <= v && v < m);
        }

        public void solve(InputReader in,PrintWriter out){
            n = in.nextInt();
            m = in.nextInt();
            a = new Character[n][m];
            for(int i = 0;i < n;++i){
                String s = in.nextLine();
                for(int j = 0;j < s.length();++j){
                    a[i][j] = s.charAt(j);
                }
            }
            for(int i = 0;i < n;++i){
                for(int j = 0;j < m;++j){
                    for(int k = 0;k < 4;++k){
                        int u = i + tx[k];
                        int v = j + ty[k];
                        if(inBoard(u,v) && a[i][j] == 'B' && a[u][v] == '.'){
                            a[u][v] = '#';
                        }
                    }
                }
            }
            boolean chk = bfs();
            out.print(chk ? "Yes\n" : "No\n");
        }

        boolean bfs(){
            boolean[][] vis = new boolean[n][m];
            Queue < Pair > que = new LinkedList<>();
            que.offer(new Pair(n - 1,m - 1));
            vis[n - 1][m - 1] = true;
            while(!que.isEmpty()){
                Pair top = que.poll();
                int u = top.u;
                int v = top.v;
                for(int k = 0;k < 4;++k){
                    int nxt_u = u + tx[k];
                    int nxt_v = v + ty[k];
                    if(inBoard(nxt_u,nxt_v)){
                        if(a[nxt_u][nxt_v] != '#' && !vis[nxt_u][nxt_v]){
                            vis[nxt_u][nxt_v] = true;
                            que.offer(new Pair(nxt_u,nxt_v));
                        }
                    }
                }
            }
            int good = 0,bad = 0,cgood = 0;
            for(int i = 0;i < n;++i){
                for(int j = 0;j < m;++j){
                    good += (a[i][j] == 'G' && vis[i][j] ? 1 : 0);
                    cgood += (a[i][j] == 'G' ? 1 : 0);
                    bad += (a[i][j] == 'B' && vis[i][j] ? 1 : 0);
                }
            }
            if(cgood == 0){
                return true;
            }
            return (a[n - 1][m - 1] != '#' && good == cgood && bad == 0);
        }

        private class Pair {
            public int u,v;
            Pair(int u,int v){
                this.u = u;
                this.v = v;
            }
        }
    }

    static class InputReader{
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream){
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        public String next(){
            while(tokenizer == null || !tokenizer.hasMoreTokens()){
                try{
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e){
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

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

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

        public String nextLine(){
            String ret_str = "";
            try {
                ret_str = reader.readLine();
            } catch (IOException e){
                e.printStackTrace();
            }
            return ret_str;
        }
    }
}


import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0)
        {
            int n=sc.nextInt();
            int m=sc.nextInt();

            char a[][]=new char[n][m];
            for(int i=0;i<n;i++)
            {
                String s=sc.next();
                for(int j=0;j<m;j++)
                {
                    a[i][j]=s.charAt(j);
                }
            }
            int f=0,g=0;
            int dx[]={1,-1,0,0};
            int dy[]={0,0,1,-1};
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<m;j++)
                {
                    if(a[i][j]=='B')
                    {
                        for(int k=0;k<4;k++)
                        {
                            int nx=i+dx[k];
                            int ny=j+dy[k];
                            if(nx>=0&&nx<n&&ny>=0&&ny<m&& a[nx][ny]=='.')
                            {
                                a[nx][ny]='#';
                            }

                        }

                    }
                }
            }

            Queue<int []> q=new LinkedList<>();
            boolean vis[][]=new boolean[n][m];

            for(int i=0;i<n;i++)
            {
                for(int j=0;j<m;j++)
                {
                    if(a[i][j]=='.')
                    {
                        q.add(new int[]{i,j});
                        vis[i][j]=true;
                    }
                }
            }

            while(!q.isEmpty())
            {
                int p[]=q.poll();
                int x=p[0],y=p[1];

                for(int k=0;k<4;k++)
                {
                    int nx=x+dx[k];
                    int ny=y+dy[k];
                    if(nx>=0&&nx<n&&ny>=0&&ny<m&& !vis[nx][ny] && a[nx][ny]!='#')
                    {
                        vis[nx][ny]=true;
                        q.add(new int[]{nx,ny});
                    }
                }

            }
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<m;j++)
                {
                    if((a[i][j]=='G'&&!vis[i][j])||(a[i][j]=='B'&&vis[i][j]))
                    {
                        f=-1;
                        break;
                    }
                }
            }
            if(f==-1)
            System.out.println("No");
            else
            System.out.println("Yes");

        }
    }
}


import java.util.*;

public class Main {
    static int n=0,m=0;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        out:
        while(t-->0)
        {
             n=sc.nextInt();
             m=sc.nextInt();

            char a[][]=new char[n][m];
            for(int i=0;i<n;i++)
            {
                String s=sc.next();
                for(int j=0;j<m;j++)
                {
                    a[i][j]=s.charAt(j);
                }
            }
            int f=0,g=0;
            int dx[]={1,-1,0,0};
            int dy[]={0,0,1,-1};
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<m;j++)
                {
                    if(a[i][j]=='B')
                    {
                        for(int k=0;k<4;k++)
                        {
                            int nx=i+dx[k];
                            int ny=j+dy[k];
                            if(nx>=0&&nx<n&&ny>=0&&ny<m&& a[nx][ny]=='.')
                            {
                                a[nx][ny]='#';
                            }
                            else if(nx>=0&&nx<n&&ny>=0&&ny<m&& a[nx][ny]=='G')
                            {
                                System.out.println("No");
                                continue out;
                            }

                        }

                    }
                }
            }

            dfs(a,n-1,m-1);

            for(int i=0;i<n;i++)
            {
                for(int j=0;j<m;j++)
                {
                    if(a[i][j]=='G')
                    {
                        f=-1;
                        break;
                    }
                }
            }
            if(f==-1)
            System.out.println("No");
            else
            System.out.println("Yes");

        }
    }

    static void dfs(char a[][],int x,int y)
    {
        if(x<0 || y<0 || x>=n || y>=m || a[x][y]=='#')
        return;

        a[x][y]='#';
        dfs(a,x-1,y);dfs(a,x+1,y);dfs(a,x,y-1);dfs(a,x,y+1);

    }

}


import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc=new Scanner(System.in);
        int t=sc.nextInt();
        while(t-->0)
        {
            int n=sc.nextInt();
            int m=sc.nextInt();

            char a[][]=new char[n][m];
            for(int i=0;i<n;i++)
            {
                String s=sc.next();
                for(int j=0;j<m;j++)
                {
                    a[i][j]=s.charAt(j);
                }
            }
            int f=0,g=0;
            int dx[]={-1,0,1,0};
            int dy[]={0,-1,0,1};
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<m;j++)
                {
                    if(a[i][j]=='B')
                    {
                        for(int k=0;k<4;k++)
                        {
                            int nx=i+dx[k];
                            int ny=j+dy[k];
                            if(nx>=0&&nx<n&&ny>=0&&ny<m&& a[nx][ny]=='.')
                            {
                                a[nx][ny]='#';
                            }

                        }

                    }
                }
            }

            Queue<int []> q=new LinkedList<>();
            boolean vis[][]=new boolean[n][m];

            for(int i=0;i<n;i++)
            {
                for(int j=0;j<m;j++)
                {
                    if(a[i][j]=='.')
                    {
                        q.add(new int[]{i,j});
                        vis[i][j]=true;
                    }
                }
            }

            while(!q.isEmpty())
            {
                int p[]=q.poll();
                int x=p[0],y=p[1];

                for(int k=0;k<4;k++)
                {
                    int nx=x+dx[k];
                    int ny=y+dy[k];
                    if(nx>=0&&nx<n&&ny>=0&&ny<m&& !vis[nx][ny] && a[nx][ny]!='#')
                    {
                        vis[nx][ny]=true;
                        q.add(new int[]{nx,ny});
                    }
                }

            }
            for(int i=0;i<n;i++)
            {
                for(int j=0;j<m;j++)
                {
                    if((a[i][j]=='G'&&!vis[i][j])||(a[i][j]=='B'&&vis[i][j]))
                    {
                        f=-1;
                        break;
                    }
                }
            }
            if(f==-1)
            System.out.println("No");
            else
            System.out.println("Yes");

        }
    }
}