package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		maze := make([]string, n)
		for i := 0; i < n; i++ {
			maze[i], _ = reader.ReadString('\n')
		}
		res := solve(n, m, maze)

		if res {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

var dd = []int{-1, 0, 1, 0, -1}

func solve(n, m int, maze []string) bool {
	good := findTarget(maze, 'G')
	if len(good) == 0 {
		return true
	}

	wall := make([][]bool, n)
	for i := 0; i < n; i++ {
		wall[i] = make([]bool, m)
		for j := 0; j < m; j++ {
			wall[i][j] = maze[i][j] == '#'
		}
	}

	N := n * m
	que := make([]int, N)
	vis := make([]bool, N)
	prison := make([]bool, N)

	block := func(bad []int) bool {
		for i := 0; i < len(vis); i++ {
			vis[i] = false
		}

		var front, end int
		que[end] = bad[0]*m + bad[1]
		end++
		vis[bad[0]*m+bad[1]] = true

		for front < end {
			cur := que[front]
			front++

			x, y := cur/m, cur%m

			for k := 0; k < 4; k++ {
				u, v := x+dd[k], y+dd[k+1]
				if u >= 0 && u < n && v >= 0 && v < m && maze[u][v] == 'B' && !vis[u*m+v] {
					que[end] = u*m + v
					end++
					vis[u*m+v] = true
				}
			}
		}

		for i := 0; i < end; i++ {
			cur := que[i]
			x, y := cur/m, cur%m
			for k := 0; k < 4; k++ {
				u, v := x+dd[k], y+dd[k+1]
				if u < 0 || u >= n || v < 0 || v >= m || wall[u][v] || maze[u][v] == 'B' {
					continue
				}
				if maze[u][v] == 'G' {
					// Bad aside with Good, not able to prion bad only
					return false
				}
				wall[u][v] = true
			}
			prison[cur] = true
		}
		return true
	}

	check := func() bool {
		for i := 0; i < len(vis); i++ {
			vis[i] = false
		}
		var front, end int
		que[end] = N - 1
		end++
		vis[N-1] = true
		var cnt int
		for front < end && cnt < len(good) {
			cur := que[front]
			front++
			x, y := cur/m, cur%m

			if wall[x][y] {
				return false
			}

			if maze[x][y] == 'G' {
				cnt++
			}

			for k := 0; k < 4; k++ {
				u, v := x+dd[k], y+dd[k+1]
				if u >= 0 && u < n && v >= 0 && v < m && !vis[u*m+v] && !wall[u][v] {
					que[end] = u*m + v
					end++
					vis[u*m+v] = true
				}
			}
		}
		return cnt == len(good)
	}

	// good person already blocked
	if !check() {
		return false
	}

	bad := findTarget(maze, 'B')

	for _, cell := range bad {
		if prison[cell[0]*m+cell[1]] {
			continue
		}
		if !block(cell) {
			return false
		}

		if !check() {
			return false
		}
	}

	return true
}

func findTarget(maze []string, x byte) [][]int {
	var res [][]int

	for i := 0; i < len(maze); i++ {
		for j := 0; j < len(maze[i]); j++ {
			if maze[i][j] == x {
				res = append(res, []int{i, j})
			}
		}
	}

	return res
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		maze := make([]string, n)
		for i := 0; i < n; i++ {
			maze[i], _ = reader.ReadString('\n')
		}
		res := solve(n, m, maze)

		if res {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

var dd = []int{-1, 0, 1, 0, -1}

func solve(n, m int, maze []string) bool {
	good := findTarget(maze, 'G')
	if len(good) == 0 {
		return true
	}

	wall := make([][]bool, n)
	for i := 0; i < n; i++ {
		wall[i] = make([]bool, m)
		for j := 0; j < m; j++ {
			wall[i][j] = maze[i][j] == '#'
		}
	}

	N := n * m
	que := make([]int, N)
	vis := make([]bool, N)
	prison := make([]bool, N)

	block := func(bad []int) bool {
		var front, end int
		que[end] = bad[0]*m + bad[1]
		end++
		vis[bad[0]*m+bad[1]] = true

		for front < end {
			cur := que[front]
			front++

			x, y := cur/m, cur%m

			for k := 0; k < 4; k++ {
				u, v := x+dd[k], y+dd[k+1]
				if u >= 0 && u < n && v >= 0 && v < m && maze[u][v] == 'B' && !vis[u*m+v] {
					que[end] = u*m + v
					end++
					vis[u*m+v] = true
				}
			}
		}

		for i := 0; i < end; i++ {
			cur := que[i]
			x, y := cur/m, cur%m
			for k := 0; k < 4; k++ {
				u, v := x+dd[k], y+dd[k+1]
				if u < 0 || u >= n || v < 0 || v >= m || wall[u][v] || maze[u][v] == 'B' {
					continue
				}
				if maze[u][v] == 'G' {
					// Bad aside with Good, not able to prion bad only
					return false
				}
				wall[u][v] = true
			}
			prison[cur] = true
			vis[cur] = false
		}
		return true
	}

	check := func() bool {

		var front, end int
		que[end] = N - 1
		end++
		vis[N-1] = true
		var cnt int
		for front < end && cnt < len(good) {
			cur := que[front]
			front++
			x, y := cur/m, cur%m

			if wall[x][y] {
				return false
			}

			if maze[x][y] == 'G' {
				cnt++
			}

			for k := 0; k < 4; k++ {
				u, v := x+dd[k], y+dd[k+1]
				if u >= 0 && u < n && v >= 0 && v < m && !vis[u*m+v] && !wall[u][v] {
					que[end] = u*m + v
					end++
					vis[u*m+v] = true
				}
			}
		}
		if cnt < len(good) {
			return false
		}

		for i := 0; i < end; i++ {
			vis[que[i]] = false
		}

		return true
	}

	bad := findTarget(maze, 'B')

	for _, cell := range bad {
		if prison[cell[0]*m+cell[1]] {
			continue
		}
		if !block(cell) {
			return false
		}
	}
	// good person already blocked
	if !check() {
		return false
	}

	return true
}

func findTarget(maze []string, x byte) [][]int {
	var res [][]int

	for i := 0; i < len(maze); i++ {
		for j := 0; j < len(maze[i]); j++ {
			if maze[i][j] == x {
				res = append(res, []int{i, j})
			}
		}
	}

	return res
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		maze := make([]string, n)
		for i := 0; i < n; i++ {
			maze[i], _ = reader.ReadString('\n')
		}
		res := solve(n, m, maze)

		if res {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

var dd = []int{-1, 0, 1, 0, -1}

func solve(n, m int, maze []string) bool {
	good := findTarget(maze, 'G')
	if len(good) == 0 {
		return true
	}

	wall := make([][]bool, n)
	for i := 0; i < n; i++ {
		wall[i] = make([]bool, m)
		for j := 0; j < m; j++ {
			wall[i][j] = maze[i][j] == '#'
		}
	}

	N := n * m
	que := make([]int, N)
	vis := make([]bool, N)
	prison := make([]bool, N)

	block := func(bad []int) bool {
		var front, end int
		que[end] = bad[0]*m + bad[1]
		end++
		vis[bad[0]*m+bad[1]] = true

		for front < end {
			cur := que[front]
			front++

			x, y := cur/m, cur%m

			for k := 0; k < 4; k++ {
				u, v := x+dd[k], y+dd[k+1]
				if u >= 0 && u < n && v >= 0 && v < m && maze[u][v] == 'B' && !vis[u*m+v] {
					que[end] = u*m + v
					end++
					vis[u*m+v] = true
				}
			}
		}

		for i := 0; i < end; i++ {
			cur := que[i]
			x, y := cur/m, cur%m
			for k := 0; k < 4; k++ {
				u, v := x+dd[k], y+dd[k+1]
				if u < 0 || u >= n || v < 0 || v >= m || wall[u][v] || maze[u][v] == 'B' {
					continue
				}
				if maze[u][v] == 'G' {
					// Bad aside with Good, not able to prion bad only
					return false
				}
				wall[u][v] = true
			}
			prison[cur] = true
			vis[cur] = false
		}
		return true
	}

	check := func() bool {

		var front, end int
		que[end] = N - 1
		end++
		vis[N-1] = true
		var cnt int
		for front < end && cnt < len(good) {
			cur := que[front]
			front++
			x, y := cur/m, cur%m

			if wall[x][y] {
				return false
			}

			if maze[x][y] == 'G' {
				cnt++
			}

			for k := 0; k < 4; k++ {
				u, v := x+dd[k], y+dd[k+1]
				if u >= 0 && u < n && v >= 0 && v < m && !vis[u*m+v] && !wall[u][v] {
					que[end] = u*m + v
					end++
					vis[u*m+v] = true
				}
			}
		}
		if cnt < len(good) {
			return false
		}

		for i := 0; i < end; i++ {
			vis[que[i]] = false
		}

		return true
	}

	// good person already blocked
	if !check() {
		return false
	}

	bad := findTarget(maze, 'B')

	for _, cell := range bad {
		if prison[cell[0]*m+cell[1]] {
			continue
		}
		if !block(cell) {
			return false
		}

		if !check() {
			return false
		}
	}

	return true
}

func findTarget(maze []string, x byte) [][]int {
	var res [][]int

	for i := 0; i < len(maze); i++ {
		for j := 0; j < len(maze[i]); j++ {
			if maze[i][j] == x {
				res = append(res, []int{i, j})
			}
		}
	}

	return res
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

type node struct {
	diff int
	time int
}

type ByTime []node

func (a ByTime) Len() int           { return len(a) }
func (a ByTime) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByTime) Less(i, j int) bool { return a[i].time < a[j].time }

var p []int
var c []int
var children [][]int
var invalid bool

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, m := 0, 0
		fmt.Fscanf(in, "%d %d\n", &n, &m)
		maze := make([][]byte, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%s\n", &maze[i])
		}
		dx := []int{0, 1, 0, -1}
		dy := []int{1, 0, -1, 0}
		ok := true
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if maze[i][j] == 'B' {
					for k := 0; k < 4; k++ {
						nx := i + dx[k]
						ny := j + dy[k]
						if nx >= 0 && nx < n && ny >= 0 && ny < m {
							if maze[nx][ny] == 'G' {
								ok = false
							} else if maze[nx][ny] == '.' {
								maze[nx][ny] = '#'
							}
						}
					}
				}
			}
		}
		if !ok {
			fmt.Fprintf(out, "No\n")
			continue
		}
		reach := make([][]bool, n)
		for i := 0; i < n; i++ {
			reach[i] = make([]bool, m)
		}
		if maze[n-1][m-1] == '.' {
			dfs(reach, maze, n-1, m-1)
		}
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if maze[i][j] == 'G' && !reach[i][j] {
					ok = false
				}
			}
		}
		if !ok {
			fmt.Fprintf(out, "No\n")
		} else {
			fmt.Fprintf(out, "Yes\n")
		}
		out.Flush()
	}
	return
}

func dfs(reach [][]bool, maze [][]byte, x, y int) {
	if reach[x][y] {
		return
	}
	reach[x][y] = true
	n := len(maze)
	m := len(maze[0])
	dx := []int{0, 1, 0, -1}
	dy := []int{1, 0, -1, 0}
	for i := 0; i < 4; i++ {
		nx := x + dx[i]
		ny := y + dy[i]
		if nx >= 0 && nx < n && ny >= 0 && ny < m {
			if maze[nx][ny] == '.' || maze[nx][ny] == 'G' {
				dfs(reach, maze, nx, ny)
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func main() {
	t := nextInt()
	for i := 0; i < t; i++ {
		n, _ := nextInt(), nextInt()
		grid := make([]string, n)
		for j := 0; j < n; j++ {
			grid[j] = next()
		}
		if solve(grid) {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

// false を返すときは、クリア不可能
func block(grid [][]byte, n, m, x, y int) bool {
	if x < 0 || x >= m || y < 0 || y >= n {
		return true
	}
	if grid[y][x] == 'G' {
		return false
	}
	if grid[y][x] == 'B' {
		return true
	}
	if grid[y][x] == '.' {
		grid[y][x] = '#'
	}
	return true
}

func blockAround(grid [][]byte, n, m, x, y int) bool {
	ret := block(grid, n, m, x-1, y)
	ret = ret && block(grid, n, m, x+1, y)
	ret = ret && block(grid, n, m, x, y-1)
	ret = ret && block(grid, n, m, x, y+1)
	return ret
}

func solve(givenGrid []string) bool {
	n := len(givenGrid)
	m := len(givenGrid[0])
	grid := make([][]byte, n)
	for i := 0; i < n; i++ {
		grid[i] = []byte(givenGrid[i])
	}

	goodPositions := [][]int{}

	for y := 0; y < n; y++ {
		for x := 0; x < m; x++ {
			if grid[y][x] == 'B' {
				// 前後左右をブロックする
				if !blockAround(grid, n, m, x, y) {
					return false
				}
			}
			if grid[y][x] == 'G' {
				goodPositions = append(goodPositions, []int{x, y})
			}
		}
	}

	if len(goodPositions) == 0 {
		return true
	}

	// good が脱出できればOK
	// Goalからつながってるところをすべて探索する。
	// 探索したところは 'x' にする
	c := dfs(grid, n, m, m-1, n-1)
	return c == len(goodPositions)
}

func dfs(grid [][]byte, n, m, x, y int) int {
	if x < 0 || x >= m || y < 0 || y >= n {
		return 0
	}
	c := 0
	if grid[y][x] == 'x' {
		return 0
	}
	if grid[y][x] == '#' {
		return 0
	}
	if grid[y][x] == 'G' {
		c++
	}
	grid[y][x] = 'x'
	c += dfs(grid, n, m, x+1, y)
	c += dfs(grid, n, m, x-1, y)
	c += dfs(grid, n, m, x, y+1)
	c += dfs(grid, n, m, x, y-1)
	return c
}

var sc = bufio.NewScanner(os.Stdin)

func init() {
	sc.Buffer(make([]byte, 256), 1e9)
	sc.Split(bufio.ScanWords)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, err := strconv.Atoi(next())
	if err != nil {
		panic(err)
	}
	return a
}

/*
URL:
https://codeforces.com/problemset/problem/1365/D
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int

	n, m int
	R    [][]rune

	N int
	G [][]int

	steps [4][2]int
)

func main() {
	steps = [4][2]int{
		[2]int{0, 1}, [2]int{0, -1}, [2]int{1, 0}, [2]int{-1, 0},
	}

	t = ReadInt()
	for i := 0; i < t; i++ {
		n, m = ReadInt2()
		R = [][]rune{}
		for j := 0; j < n; j++ {
			row := ReadRuneSlice()
			R = append(R, row)
		}

		solve()
	}
}

func solve() {
	// Gが一人もいなかったら "Yes"
	gcnt := 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if R[i][j] == 'G' {
				gcnt++
			}
		}
	}
	if gcnt == 0 {
		fmt.Println("Yes")
		return
	}

	// Bの周りを埋められるなら埋める
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if R[i][j] != 'B' {
				continue
			}

			for _, s := range steps {
				dy, dx := s[0], s[1]
				ny, nx := i+dy, j+dx

				// 埋め立て
				if 0 <= ny && ny < n && 0 <= nx && nx < m && R[ny][nx] == '.' {
					R[ny][nx] = '#'
				}
			}
		}
	}

	// グラフ作成
	N = n * m
	G = make([][]int, N)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			// 壁は無視
			if R[i][j] == '#' {
				continue
			}

			cid := m*i + j

			for _, s := range steps {
				dy, dx := s[0], s[1]
				ny, nx := i+dy, j+dx
				// 壁は駄目
				if 0 <= ny && ny < n && 0 <= nx && nx < m && R[ny][nx] != '#' {
					nid := m*ny + nx

					G[cid] = append(G[cid], nid)
				}
			}
		}
	}

	if R[n-1][m-1] == '#' {
		fmt.Println("No")
		return
	}

	// ゴールからの最短路
	// _, visited := bfs()
	_, visited := SSSPByBFS(n*m-1, N, G[:N])

	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			id := m*i + j
			// Gに到達できないときは NO
			if R[i][j] == 'G' && !visited[id] {
				fmt.Println("No")
				return
			}
			// Bに到達できるときは NO
			if R[i][j] == 'B' && visited[id] {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}

func SSSPByBFS(sid, n int, AG [][]int) (dp []int, visited []bool) {
	dp = make([]int, n)
	visited = make([]bool, n)

	for i := 0; i < n; i++ {
		dp[i] = INF_BIT30
		visited[i] = false
	}

	Q := []Node{}
	dp[sid] = 0
	visited[sid] = true
	Q = append(Q, Node{id: sid, cost: dp[sid]})

	for len(Q) > 0 {
		cnode := Q[0]
		Q = Q[1:]

		for _, nid := range G[cnode.id] {
			// 訪問済みならパス
			if visited[nid] {
				continue
			}

			dp[nid] = cnode.cost + 1
			visited[nid] = true
			Q = append(Q, Node{id: nid, cost: dp[nid]})
		}
	}

	return dp, visited
}

type Node struct {
	id, cost int
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*
URL:
https://codeforces.com/contest/1365/problem/D
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int

	n, m int
	R    [][]rune

	N int
	G [][]int

	steps [4][2]int
)

func main() {
	steps = [4][2]int{
		[2]int{0, 1}, [2]int{0, -1}, [2]int{1, 0}, [2]int{-1, 0},
	}

	t = ReadInt()
	for i := 0; i < t; i++ {
		n, m = ReadInt2()
		R = [][]rune{}
		for j := 0; j < n; j++ {
			row := ReadRuneSlice()
			R = append(R, row)
		}

		solve()
	}
}

func solve() {
	// Gが一人もいなかったら "Yes"
	gcnt := 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if R[i][j] == 'G' {
				gcnt++
			}
		}
	}
	if gcnt == 0 {
		fmt.Println("Yes")
		return
	}

	// Bの周りを埋められるなら埋める
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if R[i][j] != 'B' {
				continue
			}

			for _, s := range steps {
				dy, dx := s[0], s[1]
				ny, nx := i+dy, j+dx

				// 埋め立て
				if 0 <= ny && ny < n && 0 <= nx && nx < m && R[ny][nx] == '.' {
					R[ny][nx] = '#'
				}
			}
		}
	}
	// PrintfDebug("Grid\n")
	// for i := 0; i < n; i++ {
	// 	PrintfDebug("%s\n", string(R[i]))
	// }

	// グラフ作成
	N = n * m
	G = make([][]int, N)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			// 壁は無視
			if R[i][j] == '#' {
				continue
			}

			cid := m*i + j

			for _, s := range steps {
				dy, dx := s[0], s[1]
				ny, nx := i+dy, j+dx
				// 壁は駄目
				if 0 <= ny && ny < n && 0 <= nx && nx < m && R[ny][nx] != '#' {
					nid := m*ny + nx

					G[cid] = append(G[cid], nid)
				}
			}
		}
	}
	// PrintfDebug("testcase n: %d, m: %d\n", n, m)
	// for i := 0; i < N; i++ {
	// 	PrintfDebug("G[%d]: %v\n", i, G[i])
	// }

	// ゴールからの最短路
	_, visited := bfs()
	// PrintfDebug("visited: %v\n", visited)
	// PrintfDebug("\n")
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			id := m*i + j
			// Gに到達できないときは NO
			if R[i][j] == 'G' && !visited[id] {
				fmt.Println("No")
				return
			}
			// Bに到達できるときは NO
			if R[i][j] == 'B' && visited[id] {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}

func bfs() ([]int, []bool) {
	dp := make([]int, N)
	visited := make([]bool, N)
	gid := m*(n-1) + m - 1
	for i := 0; i < N; i++ {
		dp[i] = INF_BIT30
		visited[i] = false
	}

	Q := []Node{}
	if R[n-1][m-1] == '.' {
		dp[gid] = 0
		visited[gid] = true
		// Q := []Node{Node{id: gid, cost: dp[gid]}}
		Q = append(Q, Node{id: gid, cost: dp[gid]})
	}

	for len(Q) > 0 {
		cnode := Q[0]
		Q = Q[1:]

		for _, nid := range G[cnode.id] {
			// 訪問済みならパス
			if visited[nid] {
				continue
			}

			dp[nid] = cnode.cost + 1
			visited[nid] = true
			Q = append(Q, Node{id: nid, cost: dp[nid]})
		}
	}

	return dp, visited
}

type Node struct {
	id, cost int
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

/*
URL:
https://codeforces.com/problemset/problem/1365/D
*/

package main

import (
	"bufio"
	"errors"
	"fmt"
	"io"
	"math"
	"os"
	"strconv"
)

/********** FAU standard libraries **********/

//fmt.Sprintf("%b\n", 255) 	// binary expression

/********** I/O usage **********/

//str := ReadString()
//i := ReadInt()
//X := ReadIntSlice(n)
//S := ReadRuneSlice()
//a := ReadFloat64()
//A := ReadFloat64Slice(n)

//str := ZeroPaddingRuneSlice(num, 32)
//str := PrintIntsLine(X...)

/*******************************************************************/

const (
	// General purpose
	MOD          = 1000000000 + 7
	ALPHABET_NUM = 26
	INF_INT64    = math.MaxInt64
	INF_BIT60    = 1 << 60
	INF_INT32    = math.MaxInt32
	INF_BIT30    = 1 << 30
	NIL          = -1

	// for dijkstra, prim, and so on
	WHITE = 0
	GRAY  = 1
	BLACK = 2
)

func init() {
	// bufio.ScanWords <---> bufio.ScanLines
	ReadString = newReadString(os.Stdin, bufio.ScanWords)
	stdout = bufio.NewWriter(os.Stdout)
}

var (
	t int

	n, m int
	R    [][]rune

	N int
	G [][]int

	steps [4][2]int
)

func main() {
	steps = [4][2]int{
		[2]int{0, 1}, [2]int{0, -1}, [2]int{1, 0}, [2]int{-1, 0},
	}

	t = ReadInt()
	for i := 0; i < t; i++ {
		n, m = ReadInt2()
		R = [][]rune{}
		for j := 0; j < n; j++ {
			row := ReadRuneSlice()
			R = append(R, row)
		}

		solve()
	}
}

func solve() {
	// Gが一人もいなかったら "Yes"
	gcnt := 0
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if R[i][j] == 'G' {
				gcnt++
			}
		}
	}
	if gcnt == 0 {
		fmt.Println("Yes")
		return
	}

	// Bの周りを埋められるなら埋める
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if R[i][j] != 'B' {
				continue
			}

			for _, s := range steps {
				dy, dx := s[0], s[1]
				ny, nx := i+dy, j+dx

				// 埋め立て
				if 0 <= ny && ny < n && 0 <= nx && nx < m && R[ny][nx] == '.' {
					R[ny][nx] = '#'
				}
			}
		}
	}
	// PrintfDebug("Grid\n")
	// for i := 0; i < n; i++ {
	// 	PrintfDebug("%s\n", string(R[i]))
	// }

	// グラフ作成
	N = n * m
	G = make([][]int, N)
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			// 壁は無視
			if R[i][j] == '#' {
				continue
			}

			cid := m*i + j

			for _, s := range steps {
				dy, dx := s[0], s[1]
				ny, nx := i+dy, j+dx
				// 壁は駄目
				if 0 <= ny && ny < n && 0 <= nx && nx < m && R[ny][nx] != '#' {
					nid := m*ny + nx

					G[cid] = append(G[cid], nid)
				}
			}
		}
	}
	// PrintfDebug("testcase n: %d, m: %d\n", n, m)
	// for i := 0; i < N; i++ {
	// 	PrintfDebug("G[%d]: %v\n", i, G[i])
	// }

	// ゴールからの最短路
	_, visited := bfs()
	// PrintfDebug("visited: %v\n", visited)
	// PrintfDebug("\n")
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			id := m*i + j
			// Gに到達できないときは NO
			if R[i][j] == 'G' && !visited[id] {
				fmt.Println("No")
				return
			}
			// Bに到達できるときは NO
			if R[i][j] == 'B' && visited[id] {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}

func bfs() ([]int, []bool) {
	dp := make([]int, N)
	visited := make([]bool, N)
	gid := m*(n-1) + m - 1
	for i := 0; i < N; i++ {
		dp[i] = INF_BIT30
		visited[i] = false
	}

	Q := []Node{}
	if R[n-1][m-1] == '.' {
		dp[gid] = 0
		visited[gid] = true
		// Q := []Node{Node{id: gid, cost: dp[gid]}}
		Q = append(Q, Node{id: gid, cost: dp[gid]})
	}

	for len(Q) > 0 {
		cnode := Q[0]
		Q = Q[1:]

		for _, nid := range G[cnode.id] {
			// 訪問済みならパス
			if visited[nid] {
				continue
			}

			dp[nid] = cnode.cost + 1
			visited[nid] = true
			Q = append(Q, Node{id: nid, cost: dp[nid]})
		}
	}

	return dp, visited
}

type Node struct {
	id, cost int
}

/*******************************************************************/

/*********** I/O ***********/

var (
	// ReadString returns a WORD string.
	ReadString func() string
	stdout     *bufio.Writer
)

func newReadString(ior io.Reader, sf bufio.SplitFunc) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+9)) // for Codeforces
	r.Split(sf)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

// ReadInt returns an integer.
func ReadInt() int {
	return int(readInt64())
}
func ReadInt2() (int, int) {
	return int(readInt64()), int(readInt64())
}
func ReadInt3() (int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64())
}
func ReadInt4() (int, int, int, int) {
	return int(readInt64()), int(readInt64()), int(readInt64()), int(readInt64())
}

// ReadInt64 returns as integer as int64.
func ReadInt64() int64 {
	return readInt64()
}
func ReadInt64_2() (int64, int64) {
	return readInt64(), readInt64()
}
func ReadInt64_3() (int64, int64, int64) {
	return readInt64(), readInt64(), readInt64()
}
func ReadInt64_4() (int64, int64, int64, int64) {
	return readInt64(), readInt64(), readInt64(), readInt64()
}

func readInt64() int64 {
	i, err := strconv.ParseInt(ReadString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

// ReadIntSlice returns an integer slice that has n integers.
func ReadIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt()
	}
	return b
}

// ReadInt64Slice returns as int64 slice that has n integers.
func ReadInt64Slice(n int) []int64 {
	b := make([]int64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadInt64()
	}
	return b
}

// ReadFloat64 returns an float64.
func ReadFloat64() float64 {
	return float64(readFloat64())
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(ReadString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

// ReadFloatSlice returns an float64 slice that has n float64.
func ReadFloat64Slice(n int) []float64 {
	b := make([]float64, n)
	for i := 0; i < n; i++ {
		b[i] = ReadFloat64()
	}
	return b
}

// ReadRuneSlice returns a rune slice.
func ReadRuneSlice() []rune {
	return []rune(ReadString())
}

/*********** Debugging ***********/

// ZeroPaddingRuneSlice returns binary expressions of integer n with zero padding.
// For debugging use.
func ZeroPaddingRuneSlice(n, digitsNum int) []rune {
	sn := fmt.Sprintf("%b", n)

	residualLength := digitsNum - len(sn)
	if residualLength <= 0 {
		return []rune(sn)
	}

	zeros := make([]rune, residualLength)
	for i := 0; i < len(zeros); i++ {
		zeros[i] = '0'
	}

	res := []rune{}
	res = append(res, zeros...)
	res = append(res, []rune(sn)...)

	return res
}

// Strtoi is a wrapper of strconv.Atoi().
// If strconv.Atoi() returns an error, Strtoi calls panic.
func Strtoi(s string) int {
	if i, err := strconv.Atoi(s); err != nil {
		panic(errors.New("[argument error]: Strtoi only accepts integer string"))
	} else {
		return i
	}
}

// PrintIntsLine returns integers string delimited by a space.
func PrintIntsLine(A ...int) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.Itoa(A[i])
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintIntsLine returns integers string delimited by a space.
func PrintInts64Line(A ...int64) string {
	res := []rune{}

	for i := 0; i < len(A); i++ {
		str := strconv.FormatInt(A[i], 10) // 64bit int version
		res = append(res, []rune(str)...)

		if i != len(A)-1 {
			res = append(res, ' ')
		}
	}

	return string(res)
}

// PrintfDebug is wrapper of fmt.Fprintf(os.Stderr, format, a...)
func PrintfDebug(format string, a ...interface{}) {
	fmt.Fprintf(os.Stderr, format, a...)
}

// PrintfBufStdout is function for output strings to buffered os.Stdout.
// You may have to call stdout.Flush() finally.
func PrintfBufStdout(format string, a ...interface{}) {
	fmt.Fprintf(stdout, format, a...)
}

package main

import (
	"bufio"
	"bytes"
	. "fmt"
	"io"
	"os"
)

// github.com/EndlessCheng/codeforces-go
func CF1365D(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()
	type pair struct{ x, y int }
	dir4 := [...]pair{{-1, 0}, {1, 0}, {0, -1}, {0, 1}}

	var t, n, m int
	G := []byte{'G'}
	for Fscan(in, &t); t > 0; t-- {
		Fscan(in, &n, &m)
		cg := 0
		g := make([][]byte, n)
		for i := range g {
			Fscan(in, &g[i])
			cg += bytes.Count(g[i], G)
		}
		for i, row := range g {
			for j, c := range row {
				if c == 'B' {
					for _, d := range dir4 {
						if x, y := i+d.x, j+d.y; 0 <= x && x < n && 0 <= y && y < m && g[x][y] != 'B' {
							g[x][y] = '#'
						}
					}
				}
			}
		}
		cnt := 0
		if g[n-1][m-1] != '#' {
			g[n-1][m-1] = '#'
			for q := []pair{{n - 1, m - 1}}; len(q) > 0; {
				p := q[0]
				q = q[1:]
				for _, d := range dir4 {
					if x, y := p.x+d.x, p.y+d.y; 0 <= x && x < n && 0 <= y && y < m && g[x][y] != '#' {
						if g[x][y] == 'G' {
							cnt++
						}
						g[x][y] = '#'
						q = append(q, pair{x, y})
					}
				}
			}
		}
		if cnt == cg {
			Fprintln(out, "Yes")
		} else {
			Fprintln(out, "No")
		}
	}
}

func main() { CF1365D(os.Stdin, os.Stdout) }

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/debug"
)

type node struct {
	diff int
	time int
}

type ByTime []node

func (a ByTime) Len() int           { return len(a) }
func (a ByTime) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByTime) Less(i, j int) bool { return a[i].time < a[j].time }

var p []int
var c []int
var children [][]int
var invalid bool

func main() {
	debug.SetGCPercent(-1)

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, m := 0, 0
		fmt.Fscanf(in, "%d %d\n", &n, &m)
		maze := make([][]byte, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%s\n", &maze[i])
		}
		dx := []int{0, 1, 0, -1}
		dy := []int{1, 0, -1, 0}
		ok := true
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if maze[i][j] == 'B' {
					for k := 0; k < 4; k++ {
						nx := i + dx[k]
						ny := j + dy[k]
						if nx >= 0 && nx < n && ny >= 0 && ny < m {
							if maze[nx][ny] == 'G' {
								ok = false
							} else if maze[nx][ny] == '.' {
								maze[nx][ny] = '#'
							}
						}
					}
				}
			}
		}
		if !ok {
			fmt.Fprintf(out, "No\n")
			continue
		}
		reach := make([][]bool, n)
		for i := 0; i < n; i++ {
			reach[i] = make([]bool, m)
		}
		if maze[n-1][m-1] == '.' {
			dfs(reach, maze, n-1, m-1)
		}
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if maze[i][j] == 'G' && !reach[i][j] {
					ok = false
				}
			}
		}
		if !ok {
			fmt.Fprintf(out, "No\n")
		} else {
			fmt.Fprintf(out, "Yes\n")
		}
		out.Flush()
	}
	return
}

func dfs(reach [][]bool, maze [][]byte, x, y int) {
	if reach[x][y] {
		return
	}
	reach[x][y] = true
	n := len(maze)
	m := len(maze[0])
	dx := []int{0, 1, 0, -1}
	dy := []int{1, 0, -1, 0}
	for i := 0; i < 4; i++ {
		nx := x + dx[i]
		ny := y + dy[i]
		if nx >= 0 && nx < n && ny >= 0 && ny < m {
			if maze[nx][ny] == '.' || maze[nx][ny] == 'G' {
				dfs(reach, maze, nx, ny)
			}
		}
	}
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

func main() {
	// in, _ := os.OpenFile("cf1365D.txt", os.O_RDONLY, 0666)
	in := os.Stdin
	sc := bufio.NewScanner(in)

	var t int
	sc.Scan()
	_, _ = fmt.Sscan(sc.Text(), &t)
	for tc := 1; tc <= t; tc++ {
		// input
		var n, m int
		sc.Scan(); _, _ = fmt.Sscan(sc.Text(), &n, &m);
		var mm [][]byte = make([][]byte, n)
		for i := 0; i < n; i++ {
			mm[i] = make([]byte, m)
		}
		for i := 0; i < n; i++ {
			sc.Scan(); line := sc.Text()
			for j := 0; j < m; j++ {
				mm[i][j] = line[j]
			}
		}

		// solve
		// B주변은 이동불가지역
		gqu := list.New()
		ans := "Yes"

		here: for i, row := range mm {
			for j, cell := range row {
				if cell == 'B' {
					if i - 1 >= 0 {
						if mm[i - 1][j] == '.' { mm[i - 1][j] = '#' } else
							if mm[i - 1][j] == 'G' { ans = "No"; break here }
					}
					if i + 1 < n {
						if mm[i + 1][j] == '.' { mm[i + 1][j] = '#' } else
							if mm[i + 1][j] == 'G' { ans = "No"; break here }
					}
					if j - 1 >= 0 {
						if mm[i][j - 1] == '.' { mm[i][j - 1] = '#' } else
							if mm[i][j - 1] == 'G' { ans = "No"; break here }
					}
					if j + 1 < m {
						if mm[i][j + 1] == '.' { mm[i][j + 1] = '#' } else
							if mm[i][j + 1] == 'G' { ans = "No"; break here }
					}
				} else if cell == 'G' {
					gqu.PushBack([]int {i, j})
				}
			}
		}
		if ans == "No" {
			fmt.Println(ans)
			continue
		}

		// move g
		for gqu.Len() > 0 {
			el := gqu.Front(); gqu.Remove(el)
			v := el.Value.([]int)
			if mm[v[0]][v[1]] == 'O' {
				continue
			}

			visit := make([][]bool, n)
			for i, _ := range visit {
				visit[i] = make([]bool, m)
			}

			tqu := list.New()
			tqu.PushBack(v)
			bOk := false
			for tqu.Len() > 0 {
				el2 := tqu.Front(); tqu.Remove(el2)
				v2 := el2.Value.([]int)
				i := v2[0]; j := v2[1]
				if (i + 1 == n - 1 && j == m - 1 && (mm[i + 1][j] == '.' || mm[i + 1][j] == 'G')) ||
					(i == n - 1 && j + 1 == m - 1 && (mm[i][j + 1] == '.' || mm[i][j + 1] == 'G')) {
					bOk = true
					break;
				}
				if i + 1 < n && (mm[i + 1][j] == '.' || mm[i + 1][j] == 'G' || mm[i + 1][j] == 'O') && !visit[i + 1][j] {
					if mm[i + 1][j] == 'G' { mm[i + 1][j] = 'O'}
					visit[i + 1][j] = true
					tqu.PushBack([]int {i + 1, j})
				}
				if j + 1 < m && (mm[i][j + 1] == '.' || mm[i][j + 1] == 'G' || mm[i][j + 1] == 'O') && !visit[i][j + 1] {
					if mm[i][j + 1] == 'G' { mm[i][j + 1] = 'O'}
					visit[i][j + 1] = true
					tqu.PushBack([]int {i, j + 1})
				}
				if i - 1 >= 0 && (mm[i - 1][j] == '.' || mm[i - 1][j] == 'G' || mm[i - 1][j] == 'O') && !visit[i - 1][j] {
					if mm[i - 1][j] == 'G' { mm[i - 1][j] = 'O'}
					visit[i - 1][j] = true
					tqu.PushBack([]int {i - 1, j})
				}
				if j - 1 >= 0 && (mm[i][j - 1] == '.' || mm[i][j - 1] == 'G' || mm[i][j - 1] == 'O') && !visit[i][j - 1] {
					if mm[i][j - 1] == 'G' { mm[i][j - 1] = 'O'}
					visit[i][j - 1] = true
					tqu.PushBack([]int {i, j - 1})
				}
			}

			if !bOk {
				ans = "No"
				break
			}
		}

		fmt.Println(ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	scan := func(x ...interface{}) (n int, err error) {
		return fmt.Fscan(in, x...)
	}
	println := func(x ...interface{}) (n int, err error) {
		return fmt.Fprintln(out, x...)
	}

	var t int
	for scan(&t); t > 0; t-- {
		var n, m int
		scan(&n, &m)
		fld := make([][]byte, n)
		in.ReadString('\n')
		for i := range fld {
			s, _ := in.ReadString('\n')
			fld[i] = []byte(s)
		}
		isValidCell := func(i, j int) bool {
			return i >= 0 && i < n && j >= 0 && j < m
		}
		initiallyBad := false
		for i := range fld {
			for j := range fld[i] {
				if fld[i][j] == 'B' {
					for _, cell := range []struct{ i, j int }{
						{i - 1, j}, {i, j - 1}, {i + 1, j}, {i, j + 1}} {
						ni, nj := cell.i, cell.j
						if isValidCell(ni, nj) {
							if fld[ni][nj] == 'G' {
								initiallyBad = true
								break
							} else if fld[ni][nj] == '.' {
								fld[ni][nj] = '#'
							}
						}
					}
				}
			}
			if initiallyBad {
				break
			}
		}
		if initiallyBad {
			println("No")
			continue
		}
		bad := false
		reachable := dfsInitializer(n-1, m-1, fld, isValidCell)
		for i := range fld {
			for j := range fld[i] {
				if fld[i][j] == 'G' && !reachable[i][j] {
					bad = true
					break
				}
			}
			if bad {
				break
			}
		}
		if bad {
			println("No")
		} else {
			println("Yes")
		}
	}
}

func dfsInitializer(
	i int, j int,
	fld [][]byte, isValidCell func(int, int) bool) [][]bool {

	reachable := make([][]bool, len(fld))
	for i := range reachable {
		reachable[i] = make([]bool, len(fld[i]))
	}
	var dfs func(int, int)
	dfs = func(i, j int) {
		if fld[i][j] == '#' || reachable[i][j] {
			return
		}
		reachable[i][j] = true
		for _, cell := range []struct{ i, j int }{
			{i - 1, j}, {i, j - 1}, {i + 1, j}, {i, j + 1}} {
			ni, nj := cell.i, cell.j
			if isValidCell(ni, nj) {
				dfs(ni, nj)
			}
		}
	}
	dfs(i, j)
	return reachable
}

package main

import (
	"fmt"
)

type Board struct {
	board   []byte
	visited []bool
	width   int
	height  int
}

func MakeBoard(width, height int) Board {
	return Board{
		make([]byte, 10*width*height+3),
		make([]bool, 10*width*height+3),
		width,
		height,
	}
}
func (b *Board) set(x, y int, val byte) {
	if b.in(x,y) {
		b.board[b.from2d(x, y)] = val
	}
}
func (b *Board) get(x, y int) byte {
	if b.in(x,y) {
		return b.board[b.from2d(x, y)]
	} else {
		return 0
	}
}
func (b *Board) in(x, y int) bool {
	return x >= 0 && x < b.width && y >= 0 && y < b.height
}
func (b *Board) to2d(val int) (int, int) {
	x := val / b.height
	return x, val - x * b.height
}
func (b *Board) from2d(x, y int) int {
	val := x*b.height + y
	if val < len(b.board) {
		return val
	} else {
		return len(b.board)-1
	}
}
func (b *Board) printVisited() {
	for i := 0; i < b.width; i++ {
		for j := 0; j < b.height; j++ {
			fmt.Printf("%v|", b.visited[b.from2d(i, j)])
		}
		fmt.Println()
	}

}
func (b *Board) canBeBlocker(x, y int) bool {
	return b.in(x, y) && b.board[b.from2d(x, y)] == '.'
}
func (b *Board) bfs(x, y int) {
	if !b.in(x,y) {
		return
	}
	for i := 0; i < len(b.visited); i++ {
		b.visited[i] = false
	}
	maxx := 10*4*len(b.visited)+5
	queue := make([]int, maxx)
	queue[0] = b.from2d(x, y)
	qSize := 1
	for i := 0; i < qSize; i++ {
		current := queue[i]
		if current > len(b.board) || b.board[current] == '#' {
			continue
		}
		x, y := b.to2d(current)
		if b.in(x-1, y) && b.visited[b.from2d(x-1, y)] == false && b.board[b.from2d(x-1, y)] != '#' {
			b.visited[b.from2d(x-1, y)] = true
			queue[qSize] = b.from2d(x-1, y)
			qSize++
		}
		if b.in(x+1, y) && b.visited[b.from2d(x+1, y)] == false && b.board[b.from2d(x+1, y)] != '#' {
			b.visited[b.from2d(x+1, y)] = true
			queue[qSize] = b.from2d(x+1, y)
			qSize++
		}
		if b.in(x, y-1) && b.visited[b.from2d(x, y-1)] == false && b.board[b.from2d(x, y-1)] != '#' {
			b.visited[b.from2d(x, y-1)] = true
			queue[qSize] = b.from2d(x, y-1)
			qSize++
		}
		if b.in(x, y+1) && b.visited[b.from2d(x, y+1)] == false && b.board[b.from2d(x, y+1)] != '#' {
			b.visited[b.from2d(x, y+1)] = true
			queue[qSize] = b.from2d(x, y+1)
			qSize++
		}
	}
}

func (b *Board) isVisited(x, y int) bool {
	return b.in(x, y) && b.visited[b.from2d(x, y)]
}

func (b *Board) iterate(f func(int, int)) {
	for x := 0; x < b.width; x++ {
		for y := 0; y < b.height; y++ {
			if b.in(x,y) {
				f(x, y)
			}
		}
	}
}

func main() {
	var t int
	fmt.Scan(&t)

	for i := 0; i < t; i++ {
		var n, m int
		fmt.Scan(&n, &m)
		b := MakeBoard(n, m)
		if n <= 0 || m <= 0 {
			fmt.Println("Yes")
			continue
		}
		for i := 0; i < n; i++ {
			line := ""
			fmt.Scan(&line)
			for j := 0; j < m && j < len(line); j++ {
				b.set(i, j, line[j])
			}
		}
		b.iterate(func(x, y int) {
			if b.get(x, y) == 'B' {
				if b.canBeBlocker(x-1, y) {
					b.set(x-1, y, '#')
				}
				if b.canBeBlocker(x+1, y) {
					b.set(x+1, y, '#')
				}
				if b.canBeBlocker(x, y-1) {
					b.set(x, y-1, '#')
				}
				if b.canBeBlocker(x, y+1) {
					b.set(x, y+1, '#')
				}
			}
		})
		b.bfs(n-1, m-1)
		allVisited := true
		badVisited := false
		b.iterate(func(x, y int) {
			if b.get(x, y) == 'G' {
				allVisited = allVisited && b.isVisited(x, y)
			} else if b.get(x, y) == 'B' {
				badVisited = badVisited || b.isVisited(x, y)
			}
		})
		if allVisited && !badVisited {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

var moves = []coord{{-1, 0}, {0, 1}, {0, -1}, {1, 0}}

func solve(m maze, cgood int, bad []coord, width int, height int) string {
	for _, v := range bad {
		for _, mv := range moves {
			cc := coord{v.x + mv.x, v.y + mv.y}
			if m[cc.x][cc.y] == 2 {
				return "No"
			}
			m[cc.x][cc.y] = 0
		}
	}
	if m[width][height] == 0 {
		if cgood == 0 {
			return "Yes"
		}
		return "No"
	}
	start := []coord{{width, height}}
	seen := map[coord]struct{}{}
	indx := 0
	count := 0
	for indx < len(start) {
		v := start[indx]
		indx++
		for _, mv := range moves {
			cc := coord{v.x + mv.x, v.y + mv.y}
			_, ok := seen[cc]
			if ok {
				continue
			}
			if m[cc.x][cc.y] == 0 {
				continue
			}
			seen[cc] = struct{}{}
			if m[cc.x][cc.y] == 2 {
				count++
			}
			start = append(start, cc)
		}
	}
	if count == cgood {
		return "Yes"
	}
	return "No"
}

func output(i int, ans string) {
	fmt.Printf("%s\n", ans)
}

type maze [100][100]int

type coord struct {
	x int
	y int
}

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Buffer(make([]byte, 1000000), 1000000)
	var numTests int
	scanner.Scan()
	fmt.Sscan(scanner.Text(), &numTests)
	for i := 1; i <= numTests; i++ {
		scanner.Scan()
		var x, y int
		fmt.Sscan(scanner.Text(), &x, &y)
		m := maze{}
		cgood := 0
		bad := []coord{}
		for i := 1; i <= x; i++ {
			scanner.Scan()
			s := scanner.Text()
			for j := 1; j <= y; j++ {
				ans := string(s[j-1])
				if ans == "G" {
					m[i][j] = 2
					cgood++
				} else if ans == "B" {
					bad = append(bad, coord{i, j})
					m[i][j] = 1
				} else if ans == "." {
					m[i][j] = 1
				}
			}
		}
		output(i, solve(m, cgood, bad, x, y))
	}
}

// Author: sighduck
// URL: https://codeforces.com/contest/1365/problem/D

package main

import (
	"bufio"
	"fmt"
	"os"
)

type Cell struct {
	i int
	j int
}

func neighbors(i, j, n, m int) []Cell {
	dy := []int{-1, 0, 0, 1}
	dx := []int{0, -1, 1, 0}
	neighbors := []Cell{}
	for idx, _ := range dx {
		newI := i + dx[idx]
		newJ := j + dy[idx]
		if 0 <= newI && newI < n && 0 <= newJ && newJ < m {
			neighbors = append(neighbors, Cell{newI, newJ})
		}
	}
	return neighbors
}

func Solve(n int, m int, maze [][]rune) string {
	gCount := 0
	gi := -1
	gj := -1
	for i := 0; i < n; i++ {
		for j := 0; j < m; j++ {
			if maze[i][j] == 'G' {
				gCount += 1
				gi = i
				gj = j
			}
			neighbors := neighbors(i, j, n, m)
			for _, n := range neighbors {
				if maze[i][j] == 'B' && maze[n.i][n.j] == 'G' {
					return "No"
				} else if maze[i][j] == 'B' && maze[n.i][n.j] == '.' {
					maze[n.i][n.j] = '#'
				}
			}
		}
	}
	if gCount == 0 {
		return "Yes"
	}
	queue := []Cell{{gi, gj}}
	visited := make([][]bool, n)
	for i := 0; i < n; i++ {
		visited[i] = make([]bool, m)
	}
	visited[gi][gj] = true
	endVisited := false
	gVisited := 0
	for len(queue) > 0 {
		curr := queue[0]
		queue = queue[1:]
		if curr.i == n-1 && curr.j == m-1 {
			endVisited = true
		}
		if maze[curr.i][curr.j] == 'G' {
			gVisited += 1
		}
		for _, n := range neighbors(curr.i, curr.j, n, m) {
			if !visited[n.i][n.j] && maze[n.i][n.j] != '#' {
				queue = append(queue, n)
				visited[n.i][n.j] = true
			}
		}
	}
	if gVisited == gCount && endVisited {
		return "Yes"
	}
	return "No"
}

func main() {
	reader := bufio.NewReader(os.Stdin)
	writer := bufio.NewWriter(os.Stdout)
	defer writer.Flush()

	var t int
	fmt.Fscanf(reader, "%d\n", &t)
	for i := 0; i < t; i++ {
		var n, m int
		fmt.Fscanf(reader, "%d %d\n", &n, &m)
		maze := make([][]rune, n)
		for i := 0; i < n; i++ {
			maze[i] = make([]rune, m)
			var s string
			fmt.Fscanf(reader, "%s\n", &s)
			for j, elem := range s {
				maze[i][j] = elem
			}
		}
		fmt.Fprintf(writer, "%s\n", Solve(n, m, maze))
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
)

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	Int64() int64
	UInt64() uint64
	String() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) Int64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) UInt64() uint64 {
	impl.Scan()
	bb := impl.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) String() string {
	impl.Scan()
	return impl.Text()
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

const (
	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.Int64()
	for ; t > 0; t-- {
		n := reader.Int64()
		_ = reader.Int64()
		mat := make([][]byte, n)
		for i := range mat {
			mat[i] = []byte(reader.String())
		}
		writer.Printf("%s\n", sol(mat))
	}
}

func sol(mat [][]byte) string {
	for i := range mat {
		for j := range mat[i] {
			if mat[i][j] == 'B' {
				for _, delta := range [][2]int{
					{-1,0},
					{1,0},
					{0,-1},
					{0,1},
				}{
					dx, dy := delta[0], delta[1]
					x, y := j+dx, i+dy
					if y >= 0 && y < len(mat) && x >= 0 && x < len(mat[0]) {
						if mat[y][x] == '.' {
							mat[y][x] = '#'
							continue
						}
						if mat[y][x] == 'G' {
							return "No"
						}
						// continue if 'B' or '#'
					}
				}
				mat[i][j] = '#'
			}
		}
	}

	//debug(mat)

	// traverse and explore from bottom right
	var explore func(i, j int)
	explore = func(i, j int) {
		if mat[i][j] == 'E' || mat[i][j] == '#' {
			return
		}
		mat[i][j] = 'E'
		for _, delta := range [][2]int{
			{0,1},
			{0,-1},
			{1,0},
			{-1,0},
		}{
			dx, dy := delta[0], delta[1]
			nxtI, nxtJ := i+dy, j+dx
			if nxtI >= 0 && nxtI < len(mat) && nxtJ >= 0 && nxtJ < len(mat[nxtI]) {
				explore(nxtI, nxtJ)
			}
		}
	}
	explore(len(mat)-1, len(mat[0])-1)

	//debug(mat)

	for i := range mat {
		for j := range mat[i] {
			if mat[i][j] == 'G' {
				return "No"
			}
		}
	}
	return "Yes"
}

func debug(mat [][]byte) {
	writer.Printf("=== START MATRIX ===\n")
	for i := range mat {
		writer.Printf("%s\n", string(mat[i]))
	}
	writer.Printf("=== END MATRIX ===\n")
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	reader := bufio.NewReader(os.Stdin)

	tc := readNum(reader)

	for tc > 0 {
		tc--
		n, m := readTwoNums(reader)
		maze := make([]string, n)
		for i := 0; i < n; i++ {
			maze[i], _ = reader.ReadString('\n')
		}
		res := solve(n, m, maze)

		if res {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

func readInt(bytes []byte, from int, val *int) int {
	i := from
	sign := 1
	if bytes[i] == '-' {
		sign = -1
		i++
	}
	tmp := 0
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + int(bytes[i]-'0')
		i++
	}
	*val = tmp * sign
	return i
}

func readNum(reader *bufio.Reader) (a int) {
	bs, _ := reader.ReadBytes('\n')
	readInt(bs, 0, &a)
	return
}

func readTwoNums(reader *bufio.Reader) (a int, b int) {
	res := readNNums(reader, 2)
	a, b = res[0], res[1]
	return
}

func readThreeNums(reader *bufio.Reader) (a int, b int, c int) {
	res := readNNums(reader, 3)
	a, b, c = res[0], res[1], res[2]
	return
}

func readNNums(reader *bufio.Reader, n int) []int {
	res := make([]int, n)
	x := 0
	bs, _ := reader.ReadBytes('\n')
	for i := 0; i < n; i++ {
		for x < len(bs) && (bs[x] < '0' || bs[x] > '9') && bs[x] != '-' {
			x++
		}
		x = readInt(bs, x, &res[i])
	}
	return res
}

func readUint64(bytes []byte, from int, val *uint64) int {
	i := from

	var tmp uint64
	for i < len(bytes) && bytes[i] >= '0' && bytes[i] <= '9' {
		tmp = tmp*10 + uint64(bytes[i]-'0')
		i++
	}
	*val = tmp

	return i
}

var dd = []int{-1, 0, 1, 0, -1}

func solve(n, m int, maze []string) bool {
	good := findTarget(maze, 'G')
	if len(good) == 0 {
		return true
	}

	wall := make([][]bool, n)
	for i := 0; i < n; i++ {
		wall[i] = make([]bool, m)
		for j := 0; j < m; j++ {
			wall[i][j] = maze[i][j] == '#'
		}
	}

	N := n * m
	que := make([]int, N)
	vis := make([]bool, N)

	block := func(bad []int) bool {
		for i := 0; i < len(vis); i++ {
			vis[i] = false
		}

		var front, end int
		que[end] = bad[0]*m + bad[1]
		end++
		vis[bad[0]*m+bad[1]] = true

		for front < end {
			cur := que[front]
			front++

			x, y := cur/m, cur%m

			for k := 0; k < 4; k++ {
				u, v := x+dd[k], y+dd[k+1]
				if u >= 0 && u < n && v >= 0 && v < m && maze[u][v] == 'B' && !vis[u*m+v] {
					que[end] = u*m + v
					end++
					vis[u*m+v] = true
				}
			}
		}

		for i := 0; i < end; i++ {
			cur := que[i]
			x, y := cur/m, cur%m
			for k := 0; k < 4; k++ {
				u, v := x+dd[k], y+dd[k+1]
				if u < 0 || u >= n || v < 0 || v >= m || wall[u][v] || maze[u][v] == 'B' {
					continue
				}
				if maze[u][v] == 'G' {
					// Bad aside with Good, not able to prion bad only
					return false
				}
				wall[u][v] = true
			}
		}
		return true
	}

	check := func() bool {
		for i := 0; i < len(vis); i++ {
			vis[i] = false
		}
		var front, end int
		que[end] = N - 1
		end++
		vis[N-1] = true
		var cnt int
		for front < end && cnt < len(good) {
			cur := que[front]
			front++
			x, y := cur/m, cur%m

			if wall[x][y] {
				return false
			}

			if maze[x][y] == 'G' {
				cnt++
			}

			for k := 0; k < 4; k++ {
				u, v := x+dd[k], y+dd[k+1]
				if u >= 0 && u < n && v >= 0 && v < m && !vis[u*m+v] && !wall[u][v] {
					que[end] = u*m + v
					end++
					vis[u*m+v] = true
				}
			}
		}
		return cnt == len(good)
	}

	// good person already blocked
	if !check() {
		return false
	}

	bad := findTarget(maze, 'B')

	for _, cell := range bad {

		if !block(cell) {
			return false
		}

		if !check() {
			return false
		}
	}

	return true
}

func findTarget(maze []string, x byte) [][]int {
	var res [][]int

	for i := 0; i < len(maze); i++ {
		for j := 0; j < len(maze); j++ {
			if maze[i][j] == x {
				res = append(res, []int{i, j})
			}
		}
	}

	return res
}

package main

import (
	"bufio"
	"fmt"
	"os"
	"runtime/debug"
)

type node struct {
	diff int
	time int
}

type ByTime []node

func (a ByTime) Len() int           { return len(a) }
func (a ByTime) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByTime) Less(i, j int) bool { return a[i].time < a[j].time }

var p []int
var c []int
var children [][]int
var invalid bool

func main() {
	debug.SetGCPercent(-1)

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, m := 0, 0
		fmt.Fscanf(in, "%d %d\n", &n, &m)
		a := make([][]byte, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%s\n", &a[i])
		}
		di := []int{0, 1, 0, -1}
		dj := []int{1, 0, -1, 0}
		ok := true
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if a[i][j] == 'B' {
					for k := 0; k < 4; k++ {
						nx := i + di[k]
						ny := j + dj[k]
						if nx >= 0 && nx < n && ny >= 0 && ny < m {
							if a[nx][ny] == 'G' {
								ok = false
							} else if a[nx][ny] == '.' {
								a[nx][ny] = '#'
							}
						}
					}
				}
			}
		}
		if !ok {
			fmt.Fprintf(out, "No\n")
			continue
		}
		reach := make([][]bool, n)
		for i := 0; i < n; i++ {
			reach[i] = make([]bool, m)
		}
		if a[n-1][m-1] == '.' {
			dfs(reach, a, n-1, m-1)
		}
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if a[i][j] == 'G' && !reach[i][j] {
					ok = false
				}
			}
		}
		if !ok {
			fmt.Fprintf(out, "No\n")
		} else {
			fmt.Fprintf(out, "Yes\n")
		}
		out.Flush()
	}
	return
}

func dfs(reach [][]bool, a [][]byte, i, j int) {
	if reach[i][j] {
		return
	}
	reach[i][j] = true
	n := len(a)
	m := len(a[0])
	di := []int{0, 1, 0, -1}
	dj := []int{1, 0, -1, 0}
	for i := 0; i < 4; i++ {
		ni := i + di[i]
		nj := j + dj[i]
		if ni >= 0 && ni < n && nj >= 0 && nj < m {
			if a[ni][nj] == '.' || a[ni][nj] == 'G' {
				dfs(reach, a, ni, nj)
			}
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

type node struct {
	diff int
	time int
}

type ByTime []node

func (a ByTime) Len() int           { return len(a) }
func (a ByTime) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a ByTime) Less(i, j int) bool { return a[i].time < a[j].time }

var p []int
var c []int
var children [][]int
var invalid bool

func main() {
	//debug.SetGCPercent(-1)

	in := bufio.NewReader(os.Stdin)
	out := bufio.NewWriter(os.Stdout)
	defer out.Flush()
	t := int64(1)
	fmt.Fscanf(in, "%d\n", &t)
	for tt := int64(0); tt < t; tt++ {
		n, m := 0, 0
		fmt.Fscanf(in, "%d %d\n", &n, &m)
		a := make([][]byte, n)
		for i := 0; i < n; i++ {
			fmt.Fscanf(in, "%s\n", &a[i])
		}
		di := []int{0, 1, 0, -1}
		dj := []int{1, 0, -1, 0}
		ok := true
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if a[i][j] == 'B' {
					for k := 0; k < 4; k++ {
						nx := i + di[k]
						ny := j + dj[k]
						if nx >= 0 && nx < n && ny >= 0 && ny < m {
							if a[nx][ny] == 'G' {
								ok = false
							} else if a[nx][ny] == '.' {
								a[nx][ny] = '#'
							}
						}
					}
				}
			}
		}
		if !ok {
			fmt.Fprintf(out, "No\n")
			continue
		}
		reach := make([][]bool, n)
		for i := 0; i < n; i++ {
			reach[i] = make([]bool, m)
		}
		if a[n-1][m-1] == '.' {
			dfs(reach, a, n-1, m-1)
		}
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if a[i][j] == 'G' && !reach[i][j] {
					ok = false
				}
			}
		}
		if !ok {
			fmt.Fprintf(out, "No\n")
		} else {
			fmt.Fprintf(out, "Yes\n")
		}
		out.Flush()
	}
	return
}

func dfs(reach [][]bool, a [][]byte, i, j int) {
	if reach[i][j] {
		return
	}
	reach[i][j] = true
	n := len(a)
	m := len(a[0])
	di := []int{0, 1, 0, -1}
	dj := []int{1, 0, -1, 0}
	for i := 0; i < 4; i++ {
		ni := i + di[i]
		nj := j + dj[i]
		if ni >= 0 && ni < n && nj >= 0 && nj < m {
			if a[ni][nj] == '.' || a[ni][nj] == 'G' {
				dfs(reach, a, ni, nj)
			}
		}
	}
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

func main() {
	// in, _ := os.OpenFile("cf1365D.txt", os.O_RDONLY, 0666)
	in := os.Stdin
	sc := bufio.NewScanner(in)

	var t int
	sc.Scan()
	_, _ = fmt.Sscan(sc.Text(), &t)
	for tc := 1; tc <= t; tc++ {
		// input
		var n, m int
		sc.Scan(); _, _ = fmt.Sscan(sc.Text(), &n, &m);
		var mm [][]byte = make([][]byte, n)
		for i := 0; i < n; i++ {
			mm[i] = make([]byte, m)
		}
		for i := 0; i < n; i++ {
			sc.Scan(); line := sc.Text()
			for j := 0; j < m; j++ {
				mm[i][j] = line[j]
			}
		}

		// solve
		// B주변은 이동불가지역
		gqu := list.New()
		bqu := list.New()
		for i, row := range mm {
			for j, cell := range row {
				if cell == 'B' {
					if i - 1 >= 0 && mm[i - 1][j] == '.' { mm[i - 1][j] = '#' }
					if i + 1 < n && mm[i + 1][j] == '.' { mm[i + 1][j] = '#' }
					if j - 1 >= 0 && mm[i][j - 1] == '.' { mm[i][j - 1] = '#' }
					if j + 1 < m && mm[i][j + 1] == '.' { mm[i][j + 1] = '#' }
					bqu.PushBack([]int {i, j})
				} else if cell == 'G' {
					gqu.PushBack([]int {i, j})
				}
			}
		}

		// move g
		ans := "Yes"
		for gqu.Len() > 0 {
			el := gqu.Front(); gqu.Remove(el)
			v := el.Value.([]int)
			visit := make([][]bool, n)
			for i, _ := range visit {
				visit[i] = make([]bool, m)
			}

			tqu := list.New()
			tqu.PushBack(v)
			bOk := false
			for tqu.Len() > 0 {
				el2 := tqu.Front(); tqu.Remove(el2)
				v2 := el.Value.([]int)
				i := v2[0]; j := v2[1]
				if (i + 1 == n - 1 && j == m - 1) || (i == n - 1 && j + 1 == m - 1) {
					bOk = true
					break;
				}
				if i - 1 >= 0 && (mm[i - 1][j] == '.' || mm[i - 1][j] == 'G') && !visit[i - 1][j] {
					visit[i - 1][j] = true
					tqu.PushBack([]int {i - 1, j})
				}
				if i + 1 < n && (mm[i + 1][j] == '.' || mm[i + 1][j] == 'G') && !visit[i + 1][j] {
					visit[i + 1][j] = true
					tqu.PushBack([]int {i + 1, j})
				}
				if j - 1 >= 0 && (mm[i][j - 1] == '.' || mm[i][j - 1] == 'G') && !visit[i][j - 1] {
					visit[i][j + 1] = true
					tqu.PushBack([]int {i, j - 1})
				}
				if j + 1 >= 0 && (mm[i][j + 1] == '.' || mm[i][j + 1] == 'G') && !visit[i][j + 1] {
					visit[i][j + 1] = true
					tqu.PushBack([]int {i, j + 1})
				}
			}

			if !bOk {
				ans = "No"
				break
			}
		}

		fmt.Println(ans)
	}
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

func main() {
	// in, _ := os.OpenFile("cf1365D.txt", os.O_RDONLY, 0666)
	in := os.Stdin
	sc := bufio.NewScanner(in)

	var t int
	sc.Scan()
	_, _ = fmt.Sscan(sc.Text(), &t)
	for tc := 1; tc <= t; tc++ {
		// input
		var n, m int
		sc.Scan(); _, _ = fmt.Sscan(sc.Text(), &n, &m);
		var mm [][]byte = make([][]byte, n)
		for i := 0; i < n; i++ {
			mm[i] = make([]byte, m)
		}
		for i := 0; i < n; i++ {
			sc.Scan(); line := sc.Text()
			for j := 0; j < m; j++ {
				mm[i][j] = line[j]
			}
		}

		// solve
		// B주변은 이동불가지역
		gqu := list.New()
		bqu := list.New()
		for i, row := range mm {
			for j, cell := range row {
				if cell == 'B' {
					if i - 1 >= 0 && mm[i - 1][j] == '.' { mm[i - 1][j] = '#' }
					if i + 1 < n && mm[i + 1][j] == '.' { mm[i + 1][j] = '#' }
					if j - 1 >= 0 && mm[i][j - 1] == '.' { mm[i][j - 1] = '#' }
					if j + 1 < m && mm[i][j + 1] == '.' { mm[i][j + 1] = '#' }
					bqu.PushBack([]int {i, j})
				} else if cell == 'G' {
					gqu.PushBack([]int {i, j})
				}
			}
		}

		// move g
		ans := "Yes"
		for gqu.Len() > 0 {
			el := gqu.Front(); gqu.Remove(el)
			v := el.Value.([]int)
			visit := make([][]bool, n)
			for i, _ := range visit {
				visit[i] = make([]bool, m)
			}

			tqu := list.New()
			tqu.PushBack(v)
			bOk := false
			for tqu.Len() > 0 {
				el2 := tqu.Front(); tqu.Remove(el2)
				v2 := el2.Value.([]int)
				i := v2[0]; j := v2[1]
				if (i + 1 == n - 1 && j == m - 1 && (mm[i + 1][j] == '.' || mm[i + 1][j] == 'G')) ||
					(i == n - 1 && j + 1 == m - 1 && (mm[i][j + 1] == '.' || mm[i][j + 1] == 'G')) {
					bOk = true
					break;
				}
				if i - 1 >= 0 && (mm[i - 1][j] == '.' || mm[i - 1][j] == 'G') && !visit[i - 1][j] {
					visit[i - 1][j] = true
					tqu.PushBack([]int {i - 1, j})
				}
				if i + 1 < n && (mm[i + 1][j] == '.' || mm[i + 1][j] == 'G') && !visit[i + 1][j] {
					visit[i + 1][j] = true
					tqu.PushBack([]int {i + 1, j})
				}
				if j - 1 >= 0 && (mm[i][j - 1] == '.' || mm[i][j - 1] == 'G') && !visit[i][j - 1] {
					visit[i][j - 1] = true
					tqu.PushBack([]int {i, j - 1})
				}
				if j + 1 < m && (mm[i][j + 1] == '.' || mm[i][j + 1] == 'G') && !visit[i][j + 1] {
					visit[i][j + 1] = true
					tqu.PushBack([]int {i, j + 1})
				}
			}

			if !bOk {
				ans = "No"
				break
			}
		}

		fmt.Println(ans)
	}
}

package main

import (
	"bufio"
	"container/list"
	"fmt"
	"os"
)

func main() {
	in, _ := os.OpenFile("cf1365D.txt", os.O_RDONLY, 0666)
	// in := os.Stdin
	sc := bufio.NewScanner(in)

	var t int
	sc.Scan()
	_, _ = fmt.Sscan(sc.Text(), &t)
	for tc := 1; tc <= t; tc++ {
		// input
		var n, m int
		sc.Scan(); _, _ = fmt.Sscan(sc.Text(), &n, &m);
		var mm [][]byte = make([][]byte, n)
		for i := 0; i < n; i++ {
			mm[i] = make([]byte, m)
		}
		for i := 0; i < n; i++ {
			sc.Scan(); line := sc.Text()
			for j := 0; j < m; j++ {
				mm[i][j] = line[j]
			}
		}

		// solve
		// B주변은 이동불가지역
		gqu := list.New()
		bqu := list.New()
		for i, row := range mm {
			for j, cell := range row {
				if cell == 'B' {
					if i - 1 >= 0 && mm[i - 1][j] == '.' { mm[i - 1][j] = '#' }
					if i + 1 < n && mm[i + 1][j] == '.' { mm[i + 1][j] = '#' }
					if j - 1 >= 0 && mm[i][j - 1] == '.' { mm[i][j - 1] = '#' }
					if j + 1 < m && mm[i][j + 1] == '.' { mm[i][j + 1] = '#' }
					bqu.PushBack([]int {i, j})
				} else if cell == 'G' {
					gqu.PushBack([]int {i, j})
				}
			}
		}

		// move g
		ans := "Yes"
		for gqu.Len() > 0 {
			el := gqu.Front(); gqu.Remove(el)
			v := el.Value.([]int)
			visit := make([][]bool, n)
			for i, _ := range visit {
				visit[i] = make([]bool, m)
			}

			tqu := list.New()
			tqu.PushBack(v)
			bOk := false
			for tqu.Len() > 0 {
				el2 := tqu.Front(); tqu.Remove(el2)
				v2 := el.Value.([]int)
				i := v2[0]; j := v2[1]
				if (i + 1 == n - 1 && j == m - 1) || (i == n - 1 && j + 1 == m - 1) {
					bOk = true
					break;
				}
				if i - 1 >= 0 && (mm[i - 1][j] == '.' || mm[i - 1][j] == 'G') && !visit[i - 1][j] {
					visit[i - 1][j] = true
					tqu.PushBack([]int {i - 1, j})
				}
				if i + 1 < n && (mm[i + 1][j] == '.' || mm[i + 1][j] == 'G') && !visit[i + 1][j] {
					visit[i + 1][j] = true
					tqu.PushBack([]int {i + 1, j})
				}
				if j - 1 >= 0 && (mm[i][j - 1] == '.' || mm[i][j - 1] == 'G') && !visit[i][j - 1] {
					visit[i][j + 1] = true
					tqu.PushBack([]int {i, j - 1})
				}
				if j + 1 >= 0 && (mm[i][j + 1] == '.' || mm[i][j + 1] == 'G') && !visit[i][j + 1] {
					visit[i][j + 1] = true
					tqu.PushBack([]int {i, j + 1})
				}
			}

			if !bOk {
				ans = "No"
				break
			}
		}

		fmt.Println(ans)
	}
}

package main

import (
	"bufio"
	"fmt"
	"os"
)

type Board struct {
	board          []byte
	visited        []bool
	width          int
	height         int
	GoodGuyRemoved bool
}

func MakeBoard(width, height int) Board {
	return Board{
		make([]byte, width*height),
		make([]bool, width*height),
		width,
		height,
		false,
	}
}
func (b *Board) set(x, y int, val byte) {
	if b.board[b.from2d(x,y)] == 'G' && val != 'G' {
		b.GoodGuyRemoved = true
	}
	b.board[x*b.height+y] = val
}
func (b *Board) get(x, y int) byte {
	return b.board[x*b.height+y]
}
func (b *Board) in(x, y int) bool {
	return x >= 0 && x < b.width && y >= 0 && y < b.height
}
func (b *Board) to2d(val int) (int, int) {
	return val / b.height, val % b.height
}
func (b *Board) from2d(x, y int) int {
	return x*b.height + y
}
func (b *Board) printVisited() {
	for i := 0; i < b.width; i++ {
		for j := 0; j < b.height; j++ {
			fmt.Printf("%v|", b.visited[b.from2d(i,j)])
		}
		fmt.Println()
	}

}
func (b *Board) bfs(x, y int) {
	for i := 0; i < len(b.visited); i++ {
		b.visited[i] = false
	}
	queue := make([]int, 4*len(b.visited))
	queue[0] = b.from2d(x, y)
	qSize := 1
	for i := 0; i < qSize; i++ {
		current := queue[i]
		if b.board[current] == '#' {
			continue
		}
		x, y := b.to2d(current)
		b.visited[current] = true
		if b.in(x-1, y) && b.visited[b.from2d(x-1, y)] == false {
			queue[qSize] = b.from2d(x-1, y)
			qSize++
		}
		if b.in(x+1, y) && b.visited[b.from2d(x+1, y)] == false {
			queue[qSize] = b.from2d(x+1, y)
			qSize++
		}
		if b.in(x, y-1) && b.visited[b.from2d(x, y-1)] == false {
			queue[qSize] = b.from2d(x, y-1)
			qSize++
		}
		if b.in(x, y+1) && b.visited[b.from2d(x, y+1)] == false {
			queue[qSize] = b.from2d(x, y+1)
			qSize++
		}
	}
}

func (b *Board) isVisited(x, y int) bool {
	return b.visited[x*b.height+y]
}

func main() {
	var t int
	in := bufio.NewReader(os.Stdin)
	board := [50]string{}
	fmt.Fscan(in, &t)

	for i := 0; i < t; i++ {
		var n, m int
		fmt.Fscan(in, &n, &m)
		b := MakeBoard(n, m)
		for i := 0; i < n; i++ {
			fmt.Fscan(in, &board[i])
			for j := 0; j < m; j++ {
				b.set(i, j, board[i][j])
			}
		}
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if b.get(i, j) == 'B' {
					if b.in(i-1, j) {
						b.set(i-1, j, '#')
					}
					if b.in(i+1, j) {
						b.set(i+1, j, '#')
					}
					if b.in(i, j-1) {
						b.set(i, j-1, '#')
					}
					if b.in(i, j+1) {
						b.set(i, j+1, '#')
					}
				}
			}
		}
		b.bfs(n-1, m-1)
		allVisited := true
		for i := 0; i < n; i++ {
			for j := 0; j < m; j++ {
				if b.get(i, j) == 'G' {
					allVisited = allVisited && b.isVisited(i, j)
				}
			}
		}
		if allVisited && !b.GoodGuyRemoved {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

package main

import (
	"bufio"
	"fmt"
	"io"
	"math"
	"os"
)

type BufferedWriter interface {
	Printf(format string, a ...interface{})
	Flush()
}

type writerImpl struct {
	*bufio.Writer
}

func NewBufferedWriter(writer io.Writer) BufferedWriter {
	return &writerImpl{Writer: bufio.NewWriter(writer)}
}

func (impl *writerImpl) Printf(f string, a ...interface{}) {
	fmt.Fprintf(impl.Writer, f, a...)
}

func (impl *writerImpl) Flush() {
	impl.Writer.Flush()
}

type WordScanner interface {
	Int64() int64
	UInt64() uint64
	String() string
}

type wordScannerImpl struct {
	*bufio.Scanner
}

func NewWordScanner(reader io.Reader) WordScanner {
	s := bufio.NewScanner(reader)
	s.Split(bufio.ScanWords)
	// adjust the following size as needed
	// 2 << 17 is good enough to scan strings of len 2*10^5
	// it could go as high as 2 << 26 before cf judge breaks
	size := 2 << 20
	buf := make([]byte, size)
	s.Buffer(buf, size)
	return &wordScannerImpl{Scanner: s}
}

func (impl *wordScannerImpl) Int64() int64 {
	impl.Scan()
	bb := impl.Bytes()
	i := int64(0)
	if bb[0] == '-' {
		for _, b := range bb[1:] {
			i *= 10
			i -= int64(b - '0')
		}
		return i
	}
	for _, b := range bb {
		i *= 10
		i += int64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) UInt64() uint64 {
	impl.Scan()
	bb := impl.Bytes()
	i := uint64(0)
	for _, b := range bb {
		i *= 10
		i += uint64(b - '0')
	}
	return i
}

func (impl *wordScannerImpl) String() string {
	impl.Scan()
	return impl.Text()
}

func gcd(a, b int64) int64 {
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

func lcm(a, b int64) int64 {
	return a * b / gcd(a, b)
}

func abs(a int64) int64 {
	if a < 0 {
		return a * -1
	}
	return a
}

func min(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r < a {
			a = r
		}
	}
	return a
}

func max(a int64, rest ...int64) int64 {
	for _, r := range rest {
		if r > a {
			a = r
		}
	}
	return a
}

const (
	INF = int64(math.MaxInt64)
	MOD = 1e9 + 7
)

var reader = NewWordScanner(os.Stdin)
var writer = NewBufferedWriter(os.Stdout)

func main() {
	defer writer.Flush()
	t := reader.Int64()
	for ; t > 0; t-- {
		n := reader.Int64()
		_ = reader.Int64()
		mat := make([][]byte, n)
		for i := range mat {
			mat[i] = []byte(reader.String())
		}
		writer.Printf("%s\n", sol(mat))
	}
}

func sol(mat [][]byte) string {
	for i := range mat {
		for j := range mat[i] {
			if mat[i][j] == 'B' {
				for _, delta := range [][2]int{
					{-1,-1},
					{-1,0},
					{-1,1},
					{1,-1},
					{1,0},
					{1,1},
					{0,-1},
					{0,1},
				}{
					dx, dy := delta[0], delta[1]
					x, y := j+dx, i+dy
					if y >= 0 && y < len(mat) && x >= 0 && x < len(mat[0]) {
						if mat[y][x] == '.' {
							mat[y][x] = '#'
							continue
						}
						if mat[y][x] == 'G' {
							return "No"
						}
						// continue if 'B' or '#'
					}
				}
			}
		}
	}

	// traverse and explore from bottom right
	var explore func(i, j int)
	explore = func(i, j int) {
		if mat[i][j] == 'E' || mat[i][j] == '#' {
			return
		}
		mat[i][j] = 'E'
		for _, delta := range [][2]int{
			{0,1},
			{0,-1},
			{1,0},
			{-1,0},
		}{
			dx, dy := delta[0], delta[1]
			nxtI, nxtJ := i+dy, j+dx
			if nxtI >= 0 && nxtI < len(mat) && nxtJ >= 0 && nxtJ < len(mat[nxtI]) {
				explore(nxtI, nxtJ)
			}
		}
	}
	explore(len(mat)-1, len(mat[0])-1)

	//debug(mat)

	for i := range mat {
		for j := range mat[i] {
			if mat[i][j] == 'G' {
				return "No"
			}
		}
	}
	return "Yes"
}

func debug(mat [][]byte) {
	writer.Printf("=== START MATRIX ===\n")
	for i := range mat {
		writer.Printf("%s\n", string(mat[i]))
	}
	writer.Printf("=== END MATRIX ===\n")
}