       
        import java.util.*;
        import java.math.*;
        import java.io.*; 
         public class B{
    
            static FastReader scan=new FastReader();
           public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
  static boolean can[][];
  static char board[][];
  static boolean vis[][];
  static int n,m;
  static boolean dfs(int x,int y)
  {
    if(x==n-1&&y==m-1&&board[x][y]!='#'){
        if(x-1>=0&&board[x-1][y]=='B')
            return false;
        if(y-1>=0&&board[x][y-1]=='B')
            return false;
       // System.out.println("FUCK");
        return true;
    }
   // System.out.println
    if(x>=n)
        return false;
    if(y>=m)
        return false;
    if(x<0)
        return false;
    if(y<0)
        return false;
    if(board[x][y]=='#')
        return false;
    if(vis[x][y])
        return false;
    vis[x][y]=true;

    if(x+1<n)
    {
        if(dfs(x+1,y))
        {
            //can[x+1][y]=true;
            return true;
        }
    }
    if(x-1>=0)
    {
        if(dfs(x-1,y)){
          //  can[x-1][y]=true;
            return true;
        }
    }

    if(y+1<m)
    {

        if(dfs(x,y+1)){

           // can[x][y+1]=true;
            return true;
        }
    }
    if(y-1>=0)
    {
        if(dfs(x,y-1)){
          //  can[x][y-1]=true;
            return true;
        }
    }
    return false;

  }
        public static void main(String[] args)  throws Exception 
        {
       
        int tt=1;
    
        int T=tt;

tt=scan.nextInt();
          outer:while(tt-->0)
        {

            n=scan.nextInt();
            m=scan.nextInt();
            board=new char[n][m];
            can=new boolean[n][m];
            vis=new boolean[n][m];

              for(int i=0;i<n;i++)
                 board[i]=scan.next().toCharArray();
             for(int i=0;i<n;i++)
             {
                for(int j=0;j<m;j++)
                {
                    if(board[i][j]=='B')
                    {
                        if(i+1<n)
                        {
                            if(board[i+1][j]=='G')
                            {
                                out.println("NO");
                                continue outer;
                            }
                        }
                          if(i-1>=0)
                        {
                            if(board[i-1][j]=='G')
                            {
                                out.println("NO");
                                continue outer;
                            }
                        }
                          if(j+1<m)
                        {
                            if(board[i][j+1]=='G')
                            {
                                out.println("NO");
                                continue outer;
                            }
                        }
                          if(j-1>=0)
                        {
                            if(board[i][j-1]=='G')
                            {
                                out.println("NO");
                                continue outer;
                            }
                        }

                    }
                }
             }

             for(int i=0;i<n;i++)
             {
                for(int j=0;j<m;j++)
                {
                    if(board[i][j]=='B')
                    {
                        can=new boolean[n][m];
                        vis=new boolean[n][m];
                       // boolean lk=dfs(i,j);
                       // out.println(can[0][2]);
                        //out.println(lk);
                        if(i+1<n)
                        {
                            if(dfs(i+1,j))
                                board[i+1][j]='#';
                        }
                         if(i-1>=0)
                        {
                            if(dfs(i-1,j))
                                board[i-1][j]='#';
                        }
                         if(j+1<m)
                        {
                            if(dfs(i,j+1))
                                board[i][j+1]='#';
                        }
                         if(j-1>=0)
                        {
                            if(dfs(i,j-1))
                                board[i][j-1]='#';
                        }

                    }
                }
             }
             /*for(int i=0;i<n;i++)
             {
                for(int j=0;j<m;j++)
                {
                    out.print(board[i][j]+" ");
                }
                out.println();
             }*/
             for(int i=0;i<n;i++)
             {
                for(int j=0;j<m;j++)
                {
                    if(board[i][j]=='G')
                    {
                        vis=new boolean[n][m];
                        if(!dfs(i,j))
                        {
                            out.println("NO");
                            continue outer;
                        }
                    }
                }
             }
             out.println("YES");


        }
        out.close();



        }

        static class dsu{
            static int id[]=new int[101];
            dsu()
            {
                for(int i=0;i<101;i++)
                    id[i]=i;
            }
            static int find(int x)
            {
                if(x==id[x])
                    return x;
                return find(id[x]);
            }
            static void connect(int i,int j)
            {
                i=find(i);
                j=find(j);
                id[i]=j;
            }
            static boolean is(int i,int j)
            {
                return find(i)==find(j);
            }
        }
        static long binexp(long a,long n,long mod)
        {
            if(n==0)
               return 1;
            long res=binexp(a,n/2,mod)%mod;
            res=res*res;
            if(n%2==1)
                return (res*a)%mod;
            else 
                return res%mod;
        }
        static class special{
            Pair x;
            Pair y;
            special(Pair x,Pair y)
            {
              this.x=new Pair(x.x,x.y);
              this.y=new Pair(y.x,y.y);
            }   
              @Override
                public int hashCode() {
                    return (int)(x.x + 31 * y.y);
                }
                public boolean equals(Object other)
            {
                if(other instanceof special)
                {
                    special e =(special)other;
                    return this.x.x==e.x.x && this.x.y==e.x.y && this.y.x==e.y.x && this.y.y==e.y.y;
                }
                else return false;
            }
        }
        static long powMod(long base, long exp, long mod) {
               if (base == 0 || base == 1) return base;
               if (exp == 0) return 1;
               if (exp == 1) return base % mod;
               long R = powMod(base, exp/2, mod) % mod;
               R *= R;
               R %= mod;
               if ((exp & 1) == 1) {
                   return base * R % mod;
               }
               else return R % mod;
           }
         public static  long pow(long b, long e) {
                    long r = 1;
                    while (e > 0) {
                        if (e % 2 == 1) r = r * b ;
                        b = b * b;
                        e >>= 1;
                    }
                    return r;
                }

        private static void sort(int[] arr) {
                List<Integer> list = new ArrayList<>();
                for (int object : arr) list.add(object);
                Collections.sort(list);
                for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
            }
         public static class FastReader {
                BufferedReader br;
                StringTokenizer root;
                
         
                public FastReader() {
                    br = new BufferedReader(new InputStreamReader(System.in));
                }
                FastReader(String filename)throws Exception
                {

                    br=new BufferedReader(new FileReader(filename));
                }
         
                String next() {
                    while (root == null || !root.hasMoreTokens()) {
                        try {
                            root = new StringTokenizer(br.readLine());
                        } catch (Exception addd) {
                            addd.printStackTrace();
                        }
                    }
                    return root.nextToken();
                }
         
                int nextInt() {
                    return Integer.parseInt(next());
                }
         
                double nextDouble() {
                    return Double.parseDouble(next());
                }
         
                long nextLong() {
                    return Long.parseLong(next());
                }
         
                String nextLine() {
                    String str = "";
                    try {
                        str = br.readLine();
                    } catch (Exception addd) {
                        addd.printStackTrace();
                    }
                    return str;
                }
                 public int[] nextIntArray(int arraySize) {
                    int array[] = new int[arraySize];
         
                    for (int i = 0; i < arraySize; i++) {
                        array[i] = nextInt();
                    }
         
                    return array;
                }
        }
        public static class Pair implements Comparable<Pair>{
                 long x;
                 long y;
                 long ab;
                
                long z;
                long h;
                public Pair(){}
                public Pair(long x1, long y1,long z) {
                    x=x1;
                    y=y1;
                    this.z=z;
                }
                public Pair(long x1, long y1) {
                    x=x1;
                    y=y1;
                    this.ab=x+y;
                
                }
                public Pair(long x, long y,long z,long h) {
                    this.x=x;
                    this.y=y;
                    this.z=z;
                    this.h=h;
                
                }
                @Override
                public int hashCode() {
                    final int prime = 31;
                    int result = 1;
                    result = prime * result +(int) x;
                    result = prime * result + (int)y;
                    return result;
                }
                public String toString() {
                    return x + " " + y;
                }
                @Override
                public boolean equals(Object o){
                    if (o == this) return true;
                    if(o==null)
                        return false;
                    if (o.getClass() != getClass()) return false;
                    Pair t = (Pair)o;
                    return t.x == x && t.y == y&&t.z==z;
                }
                public  int compareTo(Pair o)
                {
                    return (int)((o.z-o.x+o.h-o.y)-(z-x+h-y));
                }
        }

        }







