← Home
package main

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

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

	var t int
	if _, err := fmt.Fscan(in, &t); err != nil {
		return
	}
	for ; t > 0; t-- {
		var n int
		fmt.Fscan(in, &n)
		grid := make([][]byte, n)
		for i := 0; i < n; i++ {
			var s string
			fmt.Fscan(in, &s)
			grid[i] = []byte(s)
		}

		bad := false
		forb := make([][]bool, n)
		for i := 0; i < n; i++ {
			forb[i] = make([]bool, n)
		}

		// Horizontal windows
		for i := 0; i < n; i++ {
			for j := 0; j+2 < n; j++ {
				cnt := 0
				dot := -1
				for k := 0; k < 3; k++ {
					if grid[i][j+k] == '#' {
						cnt++
					} else {
						dot = j + k
					}
				}
				if cnt == 3 {
					bad = true
				} else if cnt == 2 && dot != -1 {
					forb[i][dot] = true
				}
			}
		}
		// Vertical windows
		for j := 0; j < n; j++ {
			for i := 0; i+2 < n; i++ {
				cnt := 0
				dot := -1
				for k := 0; k < 3; k++ {
					if grid[i+k][j] == '#' {
						cnt++
					} else {
						dot = i + k
					}
				}
				if cnt == 3 {
					bad = true
				} else if cnt == 2 && dot != -1 {
					forb[dot][j] = true
				}
			}
		}

		if bad {
			fmt.Fprintln(out, "NO")
			continue
		}

		// Count blacks and find a start
		totalBlack := 0
		sx, sy := -1, -1
		for i := 0; i < n; i++ {
			for j := 0; j < n; j++ {
				if grid[i][j] == '#' {
					totalBlack++
					sx, sy = i, j
				}
			}
		}
		if totalBlack == 0 {
			fmt.Fprintln(out, "YES")
			continue
		}

		// Allowed cells: existing blacks or whites not forbidden
		allowed := make([][]bool, n)
		for i := 0; i < n; i++ {
			allowed[i] = make([]bool, n)
			for j := 0; j < n; j++ {
				if grid[i][j] == '#' || (grid[i][j] == '.' && !forb[i][j]) {
					allowed[i][j] = true
				}
			}
		}

		// BFS from one black over allowed cells
		qx := make([]int, 0, n*n)
		qy := make([]int, 0, n*n)
		vis := make([][]bool, n)
		for i := 0; i < n; i++ {
			vis[i] = make([]bool, n)
		}
		qx = append(qx, sx)
		qy = append(qy, sy)
		vis[sx][sy] = true
		head := 0
		dx := []int{1, -1, 0, 0}
		dy := []int{0, 0, 1, -1}
		for head < len(qx) {
			x, y := qx[head], qy[head]
			head++
			for dir := 0; dir < 4; dir++ {
				nx, ny := x+dx[dir], y+dy[dir]
				if nx < 0 || nx >= n || ny < 0 || ny >= n {
					continue
				}
				if !allowed[nx][ny] || vis[nx][ny] {
					continue
				}
				vis[nx][ny] = true
				qx = append(qx, nx)
				qy = append(qy, ny)
			}
		}

		ok := true
		for i := 0; i < n && ok; i++ {
			for j := 0; j < n; j++ {
				if grid[i][j] == '#' && !vis[i][j] {
					ok = false
					break
				}
			}
		}
		if ok {
			fmt.Fprintln(out, "YES")
		} else {
			fmt.Fprintln(out, "NO")
		}
	}
}