Read problems statements [Mandarin] , [Bengali] , [Hindi] , [Russian] and [Vietnamese] as well.

You are given a grid with $N$ rows and $M$ columns; each cell of this grid is either empty or contains an obstacle. Initially, all cells are colorless.

You may perform the following operation an arbitrary number of times (including zero): choose a $2\times 2$ square in the grid and color all four of its cells. Each cell may be colored any number of times.

You want all empty cells to be colored and all cells containing obstacles to be colorless. Find out if this state can be achieved.

------  Input ------
The first line of the input contains a single integer $T$ denoting the number of test cases. The description of $T$ test cases follows.
The first line of each test case contains two space-separated integers $N$ and $M$. 
The following $N$ lines describe the grid. Each of these lines contains a string with length $M$ containing only characters '.' (denoting an empty cell) and '#' (denoting a cell with an obstacle).

------  Output ------
For each test case, print a single line containing the string "YES" if it possible to color the grid in the required way or "NO" if it is impossible (without quotes).

------  Constraints ------
$1 ≤ T ≤ 10,000$
$2 ≤ N, M ≤ 10^{3}$
the sum of $N\cdot M$ over all test cases does not exceed $5,000,000$

------  Subtasks ------
Subtask #1 (30 points): only the first row of the grid may contain obstacles

Subtask #2 (70 points): original constraints

----- Sample Input 1 ------ 
2

3 3

..#

...

...

3 3

...

.#.

...
----- Sample Output 1 ------ 
YES

NO

Difficulty: MEDIUM_HARD
Tags: Constructive algorithms

Starter code:

Solutions:
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().strip().split())
	grid = [[0] * m for i in range(n)]
	for i in range(n):
		string = input()
		for j in range(m):
			grid[i][j] = string[j]
	marked = [[0] * m for i in range(n)]
	for i in range(n - 1):
		for j in range(m - 1):
			if grid[i][j] == '.' and grid[i + 1][j] == '.' and (grid[i][j + 1] == '.') and (grid[i + 1][j + 1] == '.'):
				marked[i][j] = 1
				marked[i + 1][j] = 1
				marked[i][j + 1] = 1
				marked[i + 1][j + 1] = 1
	found = False
	for i in range(n):
		for j in range(m):
			if marked[i][j] == 0:
				if grid[i][j] == '.':
					found = True
					print('NO')
					break
		if found:
			break
	else:
		print('YES')


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	g = [[0] * m for x in range(n)]
	for j in range(n):
		s = input()
		for k in range(m):
			g[j][k] = s[k]
	c = [[0] * m for x in range(n)]
	for a in range(n - 1):
		for b in range(m - 1):
			if g[a][b] == '.' and g[a + 1][b] == '.' and (g[a][b + 1] == '.') and (g[a + 1][b + 1] == '.'):
				c[a][b] = 1
				c[a + 1][b] = 1
				c[a][b + 1] = 1
				c[a + 1][b + 1] = 1
	f = True
	for u in range(n):
		for w in range(m):
			if c[u][w] == 0:
				if g[u][w] == '.':
					f = False
					break
	print('YES' if f else 'NO')


def condition(i, j):
	if i + 1 >= n or j + 1 >= m:
		return False
	if a[i][j] == '#':
		return False
	if a[i][j + 1] == '#':
		return False
	if a[i + 1][j] == '#':
		return False
	if a[i + 1][j + 1] == '#':
		return False
	return True

def answer():
	v = [[False for i in range(m)] for j in range(n)]
	for i in range(n):
		for j in range(m):
			if condition(i, j):
				v[i][j] = True
				v[i][j + 1] = True
				v[i + 1][j] = True
				v[i + 1][j + 1] = True
	for i in range(n):
		for j in range(m):
			if a[i][j] == '.' and (not v[i][j]):
				return 'NO'
	return 'YES'
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [input() for i in range(n)]
	print(answer())


for _ in range(int(input())):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	arr = []
	tot = 0
	col = 0
	for _ in range(0, n):
		x = input()
		tot = tot + x.count('.')
		arr.append(list(x))
	loop = (n - 1) * (m - 1)
	i = 0
	j = 0
	for _ in range(loop):
		if arr[i][j] != '#' and arr[i][j + 1] != '#' and (arr[i + 1][j] != '#') and (arr[i + 1][j + 1] != '#'):
			arr[i][j] = 1
			arr[i][j + 1] = 1
			arr[i + 1][j + 1] = 1
			arr[i + 1][j] = 1
		j += 1
		if j < m - 1:
			pass
		else:
			if i < n - 1:
				i += 1
			j = 0
	for k in arr:
		col = col + k.count(1)
	if col == tot:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	mat = []
	tot = 0
	col = 0
	for _ in range(n):
		s = input()
		tot = tot + s.count('.')
		l = list(s)
		mat.append(l)
	for i in range(n - 1):
		for j in range(m - 1):
			if (mat[i][j] == '.' or mat[i][j] == 'c') and (mat[i + 1][j] == '.' or mat[i + 1][j] == 'c') and (mat[i + 1][j + 1] == '.' or mat[i + 1][j + 1] == 'c') and (mat[i][j + 1] == '.' or mat[i][j + 1] == 'c'):
				mat[i][j] = 'c'
				mat[i + 1][j] = 'c'
				mat[i + 1][j + 1] = 'c'
				mat[i][j + 1] = 'c'
	for k in mat:
		col = col + k.count('c')
	if col == tot:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, m) = map(int, input().split(' '))
	matrix = []
	num_dots = 0
	num_has = 0
	for i in range(n):
		temp = list(input())
		matrix.append(temp)
		num_dots += temp.count('.')
		num_has += temp.count('#')
	for i in range(n):
		if i + 1 == n:
			break
		for j in range(m):
			if j + 1 == m:
				break
			elem1 = matrix[i][j]
			elem2 = matrix[i][j + 1]
			elem3 = matrix[i + 1][j]
			elem4 = matrix[i + 1][j + 1]
			if elem1 == '#' or elem2 == '#' or elem3 == '#' or (elem4 == '#'):
				pass
			else:
				matrix[i][j] = 'c'
				matrix[i][j + 1] = 'c'
				matrix[i + 1][j] = 'c'
				matrix[i + 1][j + 1] = 'c'
	num_cs = 0
	for i in range(n):
		num_cs += matrix[i].count('c')
	if num_dots == num_cs:
		print('YES')
	else:
		print('NO')


try:
	for _ in range(int(input())):
		(n, m) = map(int, input().split())
		arr = [list('#' * (m + 2))]
		for x in range(n):
			arr.append(list('#' + input() + '#'))
		arr.append(list('#' * (m + 2)))
		for i in range(1, n + 1):
			for j in range(1, m + 1):
				val = True
				if arr[i][j] == '.':
					if arr[i + 1][j] + arr[i + 1][j + 1] + arr[i][j + 1] == '...' or arr[i + 1][j] + arr[i + 1][j - 1] + arr[i][j - 1] == '...' or arr[i - 1][j] + arr[i - 1][j - 1] + arr[i][j - 1] == '...' or (arr[i - 1][j] + arr[i - 1][j + 1] + arr[i][j + 1] == '...'):
						val = True
					else:
						val = False
				if val == False:
					break
			if val == False:
				break
		print('NO' if val == False else 'YES')
except:
	pass


for i in range(int(input())):
	(n, m) = list(map(int, input().split()))
	lst = []
	for i in range(n):
		lst.append(list(input()))
	for i in range(n):
		for j in range(m):
			if lst[i][j] == '.':
				lst[i][j] = 0
			else:
				lst[i][j] = 3
	for i in range(n - 1):
		for j in range(m - 1):
			if lst[i][j] == 3 or lst[i + 1][j] == 3 or lst[i][j + 1] == 3 or (lst[i + 1][j + 1] == 3):
				continue
			else:
				if lst[i][j] == 0:
					lst[i][j] += 1
				if lst[i + 1][j] == 0:
					lst[i + 1][j] += 1
				if lst[i][j + 1] == 0:
					lst[i][j + 1] += 1
				if lst[i + 1][j + 1] == 0:
					lst[i + 1][j + 1] += 1
	s = 0
	for i in lst:
		count = sum(i) - i.count(3) * 3
		if count != m - i.count(3):
			s += 1
	if s == 0:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	(n, m) = map(int, input().split())
	mat = []
	dots = 0
	has = 0
	for i in range(n):
		l = list(input())
		mat.append(l)
		dots += l.count('.')
		has += l.count('#')
	for i in range(n):
		if i + 1 == n:
			break
		for j in range(m):
			if j + 1 == m:
				break
			e1 = mat[i][j]
			e2 = mat[i + 1][j]
			e3 = mat[i][j + 1]
			e4 = mat[i + 1][j + 1]
			if e1 == '#' or e2 == '#' or e3 == '#' or (e4 == '#'):
				continue
			else:
				mat[i][j] = 'g'
				mat[i + 1][j] = 'g'
				mat[i][j + 1] = 'g'
				mat[i + 1][j + 1] = 'g'
	org = 0
	for i in range(n):
		org += mat[i].count('g')
	if org == dots:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = []
	c = 0
	for _ in range(n):
		a.append(list(input()))
	for i in range(1, n):
		for j in range(m - 1):
			if a[i][j] != '#' and a[i - 1][j] != '#' and (a[i - 1][j + 1] != '#') and (a[i][j + 1] != '#'):
				a[i][j] = 0
				a[i - 1][j] = 0
				a[i - 1][j + 1] = 0
				a[i][j + 1] = 0
	for i in range(n):
		for j in range(m):
			if a[i][j] == '.':
				c = 1
				break
	if c == 1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	flag = 1
	(r, c) = map(int, input().split())
	a = [[0 for col in range(c)] for row in range(r)]
	for i in range(r):
		s = str(input())
		for j in range(c):
			a[i][j] = s[j]
	for i in range(r - 1):
		for j in range(c - 1):
			if a[i][j] == '.' or a[i][j] == 'C':
				if (a[i][j + 1] == '.' or a[i][j + 1] == 'C') and (a[i + 1][j] == '.' or a[i + 1][j] == 'C') and (a[i + 1][j + 1] == '.' or a[i + 1][j + 1] == 'C'):
					a[i][j] = 'C'
					a[i + 1][j] = 'C'
					a[i][j + 1] = 'C'
					a[i + 1][j + 1] = 'C'
	for i in range(r):
		if '.' in a[i]:
			flag = 0
			break
	if flag == 1:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	arr = []
	ans = 0
	for i in range(n):
		arr.append(list(input()))
	ans = arr[-1].count('#')
	for i in range(n):
		if arr[i][-1] == '#':
			ans += 1
	if arr[-1][-1] == '#':
		ans -= 1
	flag = False
	cu = 0
	for i in range(n - 1):
		for j in range(m - 1):
			if (arr[i][j] == '.' or arr[i][j] == '1') and (arr[i][j + 1] == '.' or arr[i][j + 1] == '1') and (arr[i + 1][j] == '.' or arr[i + 1][j] == '1') and (arr[i + 1][j + 1] == '.' or arr[i + 1][j + 1] == '1'):
				if arr[i][j] == '.':
					arr[i][j] = '1'
					cu += 1
				if arr[i][j + 1] == '.':
					arr[i][j + 1] = '1'
					cu += 1
				if arr[i + 1][j] == '.':
					arr[i + 1][j] = '1'
					cu += 1
				if arr[i + 1][j + 1] == '.':
					arr[i + 1][j + 1] = '1'
					cu += 1
			elif arr[i][j] == '#':
				ans += 1
	ans = n * m - ans
	if cu == ans:
		print('YES')
	else:
		print('NO')


def show(t):
	for _ in range(t):
		(n, m) = map(int, input().rstrip().split())
		flag = 1
		a = [['.' for column in range(m)] for row in range(n)]
		for i in range(n):
			s = input()
			for j in range(m):
				a[i][j] = s[j]
			s = ''
		for i in range(n - 1):
			for j in range(m - 1):
				if a[i][j] != '#' and a[i + 1][j] != '#' and (a[i][j + 1] != '#') and (a[i + 1][j + 1] != '#'):
					a[i][j] = 'c'
					a[i + 1][j] = 'c'
					a[i][j + 1] = 'c'
					a[i + 1][j + 1] = 'c'
		for i in range(n):
			for j in range(m):
				if a[i][j] == '.':
					flag = 0
					break
		if flag == 0:
			print('NO')
		else:
			print('YES')
show(int(input()))


def is_safe(mat, i, j):
	if i >= 0 and j >= 0 and (i < len(mat)) and (j < len(mat[0])) and (mat[i][j] != '#'):
		return True
	return False
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	mat = []
	for _ in range(n):
		s = input()
		l = [i for i in s]
		mat.append(l)
	main_f = 1
	for i in range(n):
		for j in range(m):
			f = 0
			if mat[i][j] == '.':
				if is_safe(mat, i, j + 1) and is_safe(mat, i + 1, j + 1) and is_safe(mat, i + 1, j):
					f = 1
				elif is_safe(mat, i, j - 1) and is_safe(mat, i + 1, j) and is_safe(mat, i + 1, j - 1):
					f = 1
				elif is_safe(mat, i - 1, j - 1) and is_safe(mat, i, j - 1) and is_safe(mat, i - 1, j):
					f = 1
				elif is_safe(mat, i - 1, j) and is_safe(mat, i - 1, j + 1) and is_safe(mat, i, j + 1):
					f = 1
				if not f:
					main_f = 0
					break
		if not main_f:
			print('NO')
			break
	if main_f:
		print('YES')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = []
	value = []
	value = [[False] * m for _ in range(n)]
	arr = [[0] * m for _ in range(n)]
	for i in range(n):
		lt = input()
		for j in range(m):
			arr[i][j] = lt[j]
	for i in range(n - 1):
		for j in range(m - 1):
			if arr[i][j] != '#' and arr[i][j + 1] != '#' and (arr[i + 1][j] != '#') and (arr[i + 1][j + 1] != '#'):
				value[i][j] = True
				value[i][j + 1] = True
				value[i + 1][j] = True
				value[i + 1][j + 1] = True
	result = 0
	for i in range(n):
		for j in range(m):
			if arr[i][j] == '.' and value[i][j] != True:
				result += 1
				break
	if result == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	mat = [[0] * m for _ in range(n)]
	for i in range(n):
		lt = input()
		for j in range(m):
			mat[i][j] = lt[j]
	flag = True
	f = 0
	for i in range(n):
		for j in range(m):
			flag = False
			if mat[i][j] == '#':
				continue
			if j + 1 < m and i + 1 < n and (not flag):
				if mat[i + 1][j] == '.' and mat[i][j + 1] == '.' and (mat[i + 1][j + 1] == '.'):
					flag = True
			if j - 1 > -1 and i + 1 < n and (not flag):
				if mat[i + 1][j] == '.' and mat[i][j - 1] == '.' and (mat[i + 1][j - 1] == '.'):
					flag = True
			if j + 1 < m and i - 1 > -1 and (not flag):
				if mat[i - 1][j] == '.' and mat[i][j + 1] == '.' and (mat[i - 1][j + 1] == '.'):
					flag = True
			if j - 1 > -1 and i - 1 > -1 and (not flag):
				if mat[i - 1][j] == '.' and mat[i][j - 1] == '.' and (mat[i - 1][j - 1] == '.'):
					flag = True
			if not flag:
				f = 1
				break
	if f == 0:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	coloured = [[0 for j in range(m)] for i in range(n)]
	grid = []
	for i in range(n):
		grid.append(list(input()))
	for i in range(n - 1):
		for j in range(m - 1):
			if grid[i][j] != '#' and grid[i][j + 1] != '#' and (grid[i + 1][j] != '#') and (grid[i + 1][j + 1] != '#'):
				coloured[i][j] = 1
				coloured[i][j + 1] = 1
				coloured[i + 1][j] = 1
				coloured[i + 1][j + 1] = 1

	def is_good(grid, n, m):
		for i in range(n):
			for j in range(m):
				if grid[i][j] == '.' and coloured[i][j] == 0:
					return 'NO'
		return 'YES'
	print(is_good(grid, n, m))


def inrange(i, j, N, M, m):
	if i < N and i > -1 and (j < M) and (j > -1):
		if m[i][j] == '.':
			return True
		else:
			return False
	else:
		return False

def poss(i, j, N, M, m):
	if inrange(i - 1, j - 1, N, M, m) and inrange(i, j - 1, N, M, m) and inrange(i - 1, j, N, M, m):
		return True
	if inrange(i - 1, j, N, M, m) and inrange(i - 1, j + 1, N, M, m) and inrange(i, j + 1, N, M, m):
		return True
	if inrange(i, j - 1, N, M, m) and inrange(i + 1, j - 1, N, M, m) and inrange(i + 1, j, N, M, m):
		return True
	if inrange(i, j + 1, N, M, m) and inrange(i + 1, j, N, M, m) and inrange(i + 1, j + 1, N, M, m):
		return True
	return False

def main():
	T = int(input())
	for i in range(T):
		(N, M) = [int(item) for item in input().split()]
		matrix = [0] * N
		for j in range(N):
			matrix[j] = list(input())
		check = [[0] * M for i in range(N)]
		for i in range(N):
			for j in range(M):
				if matrix[i][j] == '#':
					check[i][j] = 1
				elif poss(i, j, N, M, matrix):
					check[i][j] = 1
		f = True
		for i in range(N):
			if not all(check[i]):
				f = False
				break
		print('YES' if f else 'NO')
main()


test = int(input())
ans = []
for i in range(test):
	p = list(map(int, input().split()))
	t = []
	for j in range(p[0]):
		s = input()
		t.append([])
		for r in range(p[1]):
			t[j].append(s[r])
	flag = 0
	for x in range(p[0]):
		if flag == 1:
			break
		for y in range(p[1]):
			if t[x][y] == '.':
				if x + 1 < p[0] and y + 1 < p[1] and (t[x + 1][y] == '.') and (t[x + 1][y + 1] == '.') and (t[x][y + 1] == '.'):
					flag = 0
				elif x > 0 and y > 0 and (t[x - 1][y] == '.') and (t[x - 1][y - 1] == '.') and (t[x][y - 1] == '.'):
					flag = 0
				elif x + 1 < p[0] and y > 0 and (t[x + 1][y] == '.') and (t[x + 1][y - 1] == '.') and (t[x][y - 1] == '.'):
					flag = 0
				elif x > 0 and y + 1 < p[1] and (t[x - 1][y] == '.') and (t[x - 1][y + 1] == '.') and (t[x][y + 1] == '.'):
					flag = 0
				else:
					flag = 1
			if flag == 1:
				ans.append('NO')
				break
	if flag == 0:
		ans.append('YES')
for v in ans:
	print(v)


import sys

def _int():
	return int(sys.stdin.readline())

def _ints():
	return map(int, sys.stdin.readline().split())

def _chars():
	return sys.stdin.readline().strip('\n')

def _intarr():
	return list(map(int, sys.stdin.readline().split()))

def _str():
	return sys.stdin.readline()

def _strarr():
	return sys.stdin.readline().split()
t = _int()
ans = []
for x in range(t):
	(n, m) = _ints()
	g = []
	for _ in range(n):
		row = list(_chars())
		g.append(row)
	for i in range(n - 1):
		for j in range(m - 1):
			if g[i][j] in ['.', 'x'] and g[i + 1][j] in ['.', 'x'] and (g[i][j + 1] in ['.', 'x']) and (g[i + 1][j + 1] in ['.', 'x']):
				(g[i][j], g[i + 1][j], g[i][j + 1], g[i + 1][j + 1]) = ['x', 'x', 'x', 'x']
	passed = True
	for i in range(n):
		for j in range(m):
			if g[i][j] == '.':
				passed = False
				break
		if not passed:
			break
	ans.append(passed)
for a in ans:
	print('YES' if a else 'NO')


for i in range(int(input())):
	(n, m) = map(int, input().split())
	f = [x for x in input()]
	flag = 'YES'
	for i in range(n - 1):
		s = [x for x in input()]
		for j in range(m - 1):
			if f[j] != '#' and f[j + 1] != '#' and (s[j] != '#') and (s[j + 1] != '#'):
				f[j] = '1'
				f[j + 1] = '1'
				s[j] = '1'
				s[j + 1] = '1'
		if '.' in f:
			flag = 'NO'
			for x in range(n - i - 2):
				input()
			break
		else:
			f = s
	if '.' in s:
		flag = 'NO'
	print(flag)


t = int(input())
while t > 0:
	t = t - 1
	(n, m) = map(int, input().split())
	L = []
	for i in range(n):
		L.append([j for j in input()])
	for i in range(n - 1):
		for j in range(m - 1):
			if L[i][j] == '#' or L[i + 1][j] == '#' or L[i][j + 1] == '#' or (L[i + 1][j + 1] == '#'):
				continue
			else:
				L[i][j] = '0'
				L[i + 1][j] = '0'
				L[i][j + 1] = '0'
				L[i + 1][j + 1] = '0'
	f = 0
	for i in range(n):
		for j in range(m):
			if L[i][j] == '.':
				f = 1
				break
		if f:
			break
	print('YNEOS'[f::2])


def check(n, m, a):
	flag = 0
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if a[i][j] == 0:
				continue
			if (a[i][j] == 0 or a[i][j - 1] == 0 or a[i - 1][j - 1] == 0 or (a[i - 1][j] == 0)) and (a[i][j] == 0 or a[i - 1][j] == 0 or a[i - 1][j + 1] == 0 or (a[i][j + 1] == 0)) and (a[i][j] == 0 or a[i][j + 1] == 0 or a[i + 1][j] == 0 or (a[i + 1][j + 1] == 0)) and (a[i][j] == 0 or a[i][j - 1] == 0 or a[i + 1][j - 1] == 0 or (a[i + 1][j] == 0)):
				flag = 1
	return flag
t = int(input())
while t > 0:
	y = 0
	tc = list((int(i) for i in input().split()))
	n = tc[0]
	m = tc[1]
	a = [[] for y in range(n + 2)]
	for i in range(n + 2):
		for j in range(m + 2):
			a[i].append(0)
	for i in range(1, n + 1):
		c = input()
		for j in range(0, len(c)):
			if c[j] == '.':
				a[i][j + 1] = 1
			else:
				a[i][j + 1] = 0
	y = check(n, m, a)
	if y == 0:
		print('YES')
	else:
		print('NO')
	t -= 1


T = int(input())
for i in range(T):
	(N, M) = [int(i) for i in input().split()]
	A = [0] * N
	B = [0] * N
	for i in range(N):
		A[i] = input()
		B[i] = list(A[i])
	k = 0
	for i in range(1, N):
		for j in range(1, M):
			if (B[i][j] == '.' or B[i][j] == '%') and (B[i - 1][j] == '.' or B[i - 1][j] == '%') and (B[i - 1][j - 1] == '.' or B[i - 1][j - 1] == '%') and (B[i][j - 1] == '.' or B[i][j - 1] == '%'):
				B[i][j] = '%'
				B[i - 1][j] = '%'
				B[i - 1][j - 1] = '%'
				B[i][j - 1] = '%'
			elif B[i][j] == '#':
				continue
	for i in range(N):
		for j in range(M):
			if B[i][j] == '.':
				k = k + 1
	if k >= 1:
		print('NO')
	else:
		print('YES')


t = input()
for i in range(int(t)):
	(m, n) = map(int, input().split())
	grid = []
	results = []
	for j in range(m):
		grid.append(list(input()))
		values = []
		for k in grid[-1]:
			if k == '.':
				values.append(0)
			else:
				values.append(-1)
		results.append(values)
	for i in range(m - 1):
		for j in range(n - 1):
			check = [grid[i][j], grid[i + 1][j], grid[i][j + 1], grid[i + 1][j + 1]]
			if '#' not in check:
				results[i][j] += 1
				results[i + 1][j] += 1
				results[i][j + 1] += 1
				results[i + 1][j + 1] += 1
	flag = 0
	for j in results:
		if 0 in j:
			flag = 1
	if flag:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(r, c) = map(int, input().split())
	a = []
	for i in range(r):
		a.append(list(input()))
	for i in range(r - 1):
		for j in range(c - 1):
			if a[i][j] != '#' and a[i + 1][j] != '#' and (a[i][j + 1] != '#') and (a[i + 1][j + 1] != '#'):
				a[i][j] = 'c'
				a[i + 1][j] = 'c'
				a[i][j + 1] = 'c'
				a[i + 1][j + 1] = 'c'
	res = True
	for i in range(r):
		for j in range(c):
			if a[i][j] == '.':
				res = False
				break
	if res:
		print('YES')
	else:
		print('NO')


from array import *
T = int(input())
for t in range(T):
	(x, y) = map(int, input().split())
	arr2d = [input() for i in range(x)]
	flag = 1
	for i in range(x):
		if flag == 1:
			for j in range(y):
				flag1 = 0
				if arr2d[i][j] == '.':
					if i - 1 >= 0 and j + 1 < y and (flag1 == 0):
						if arr2d[i - 1][j] == '.' and arr2d[i][j + 1] == '.' and (arr2d[i - 1][j + 1] == '.'):
							flag1 = 1
					if i - 1 >= 0 and j - 1 >= 0 and (flag1 == 0):
						if arr2d[i - 1][j] == '.' and arr2d[i][j - 1] == '.' and (arr2d[i - 1][j - 1] == '.'):
							flag1 = 1
					if i + 1 < x and j + 1 < y and (flag1 == 0):
						if arr2d[i + 1][j] == '.' and arr2d[i][j + 1] == '.' and (arr2d[i + 1][j + 1] == '.'):
							flag1 = 1
					if i + 1 < x and j - 1 >= 0 and (flag1 == 0):
						if arr2d[i + 1][j] == '.' and arr2d[i][j - 1] == '.' and (arr2d[i + 1][j - 1] == '.'):
							flag1 = 1
					if flag1 == 0:
						print('NO')
						flag = 0
						break
	if flag == 1:
		print('YES')


def main():
	t = int(input())
	while t:
		(n, m) = [int(x) for x in input().split()]
		a = [input() for _ in range(n)]
		b = [[0 if a[i][j] == '.' else 1 for j in range(m)] for i in range(n)]
		for i in range(n - 1):
			for j in range(m - 1):
				if a[i][j] == '.' and a[i][j + 1] == '.' and (a[i + 1][j] == '.') and (a[i + 1][j + 1] == '.'):
					b[i][j] = 1
					b[i][j + 1] = 1
					b[i + 1][j] = 1
					b[i + 1][j + 1] = 1
		flag = False
		for i in range(n):
			for j in range(m):
				if b[i][j] == 0:
					print('NO')
					flag = True
					break
			if flag:
				break
		else:
			print('YES')
		t -= 1
main()


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = []
	c = 1
	grid = {}
	for j in range(n):
		a = input()
		for k in a:
			if grid.get(c) == None:
				grid[c] = 0
			if k == '#':
				grid[c] = -1
			c += 1
	for i in grid:
		if i >= n * m - m + 1:
			break
		if i % m == 0:
			if grid[i] != -1 and grid[i - 1] != -1 and (grid[i + m] != -1) and (grid[i + m - 1] != -1):
				(grid[i], grid[i - 1], grid[i + m], grid[i - 1 + m]) = (1, 1, 1, 1)
		elif grid[i] != -1 and grid[i + 1] != -1 and (grid[i + m] != -1) and (grid[i + m + 1] != -1):
			(grid[i], grid[i + 1], grid[i + m], grid[i + 1 + m]) = (1, 1, 1, 1)
	if 0 in grid.values():
		print('NO')
	else:
		print('YES')


t = int(input())
ans = []
for i in range(t):
	(n, m) = map(int, input().split(' '))
	l = []
	temp = 0
	for j in range(n):
		l.append(list(str(input())))
	for j in range(n - 1):
		for k in range(m - 1):
			if (l[j][k] == '.' or l[j][k] == 'c') and (l[j][k + 1] == '.' or l[j][k + 1] == 'c') and (l[j + 1][k] == '.' or l[j + 1][k] == 'c') and (l[j + 1][k + 1] == '.' or l[j + 1][k + 1] == 'c'):
				l[j][k] = 'c'
				l[j][k + 1] = 'c'
				l[j + 1][k] = 'c'
				l[j + 1][k + 1] = 'c'
	for j in range(n):
		for k in range(m):
			if l[j][k] == '.':
				temp = 1
				break
	if temp == 0:
		ans.append('YES')
	else:
		ans.append('NO')
print(*ans, sep='\n')


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	arr = []
	for j in range(n):
		stri = list(input())
		arr.append(stri)
	new = []
	for k in range(n):
		new.append([])
		for l in range(m):
			new[k].append(4)
	new[0][0] = 1
	new[0][m - 1] = 1
	new[n - 1][0] = 1
	new[n - 1][m - 1] = 1
	for j in range(1, m - 1):
		new[0][j] = 2
		new[n - 1][j] = 2
	for j in range(1, n - 1):
		new[j][0] = 2
		new[j][m - 1] = 2
	for k in range(n - 1):
		for l in range(m - 1):
			if arr[k][l] == '#' or arr[k][l + 1] == '#' or arr[k + 1][l] == '#' or (arr[k + 1][l + 1] == '#'):
				new[k][l] -= 1
				new[k][l + 1] -= 1
				new[k + 1][l] -= 1
				new[k + 1][l + 1] -= 1
	flag = 1
	for k in range(n):
		for l in range(m):
			if new[k][l] <= 0 and arr[k][l] == '.':
				flag = 0
	if flag == 0:
		print('NO')
	else:
		print('YES')


from math import *
from copy import *
from string import *
from sys import stdin
from itertools import *
T = int(input())
for _ in range(T):
	(N, M) = map(int, input().split())
	a = []
	c = []
	flag = 0
	for i in range(N):
		a.append(list(input()))
	for i in range(N - 1):
		for j in range(M - 1):
			if (a[i][j] == '.' or a[i][j] == 1) and (a[i + 1][j] == '.' or a[i + 1][j] == 1) and (a[i][j + 1] == '.' or a[i][j + 1] == 1) and (a[i + 1][j + 1] == '.' or a[i + 1][j + 1] == 1):
				a[i][j] = 1
				a[i + 1][j] = 1
				a[i][j + 1] = 1
				a[i + 1][j + 1] = 1
	for i in range(N):
		for j in range(M):
			if a[i][j] != '#':
				if a[i][j] != 1:
					flag = 1
					break
	if flag:
		print('NO')
	else:
		print('YES')


for testcases in range(int(input())):
	isPsbl = True
	[n, m] = [int(x) for x in input().split()]
	arr = []
	for row in range(n):
		arr.append(input())
	for row in range(n):
		for col in range(m):
			if arr[row][col] == '.':
				ct = 0
				if row > 0 and col > 0 and (arr[row - 1][col] == '.' and arr[row - 1][col - 1] == '.' and (arr[row][col - 1] == '.')):
					ct += 1
				if row > 0 and col < m - 1 and (arr[row - 1][col] == '.' and arr[row - 1][col + 1] == '.' and (arr[row][col + 1] == '.')):
					ct += 1
				if row < n - 1 and col < m - 1 and (arr[row][col + 1] == '.' and arr[row + 1][col + 1] == '.' and (arr[row + 1][col] == '.')):
					ct += 1
				if row < n - 1 and col > 0 and (arr[row + 1][col] == '.' and arr[row + 1][col - 1] == '.' and (arr[row][col - 1] == '.')):
					ct += 1
				if ct == 0:
					isPsbl = False
					break
			else:
				continue
		if not isPsbl:
			break
	print('YES' if isPsbl else 'NO')


for i in range(int(input())):
	(n, m) = map(int, input().strip().split(' '))
	lst = []
	for j in range(n):
		l = list(input())
		lst.append(l)
	for j in range(n - 1):
		for k in range(m - 1):
			if lst[j][k] != '#' and lst[j][k + 1] != '#' and (lst[j + 1][k] != '#') and (lst[j + 1][k + 1] != '#'):
				lst[j][k] = '1'
				lst[j][k + 1] = '1'
				lst[j + 1][k] = '1'
				lst[j + 1][k + 1] = '1'
	c = 1
	p = 0
	for j in range(n):
		for k in range(m):
			if lst[j][k] == '.':
				c = 0
				break
			elif lst[j][k] == '#':
				p = 1 + p
	if c == 1 and p != n * m:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, m) = input().split()
	(n, m) = (int(n), int(m))
	l = []
	for i in range(n):
		s = input()
		l1 = []
		for j in range(m):
			l1.append(s[j])
		l.append(l1)
	for i in range(n - 1):
		for j in range(m - 1):
			if l[i][j] == '#' or l[i + 1][j] == '#' or l[i][j + 1] == '#' or (l[i + 1][j + 1] == '#'):
				continue
			else:
				l[i][j] = 1
				l[i][j + 1] = 1
				l[i + 1][j] = 1
				l[i + 1][j + 1] = 1
	f = 0
	for i in range(n):
		for j in range(m):
			if l[i][j] == '.':
				f = 1
				break
	if f:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(n, m) = map(int, input().split(' '))
	l = []
	z = []
	for i in range(n):
		z.append([-1] * m)
	check = True
	for i in range(n):
		l2 = list(input())
		l.append(l2)
	for i in range(n - 1):
		for j in range(m - 1):
			if l[i][j] == '.':
				if l[i][j + 1] == '.' and l[i + 1][j + 1] == '.' and (l[i + 1][j] == '.'):
					z[i][j] = 1
					z[i][j + 1] = 1
					z[i + 1][j] = 1
					z[i + 1][j + 1] = 1
	for i in range(n):
		for j in range(m):
			if l[i][j] == '.' and z[i][j] != 1:
				check = False
				break
		if check == False:
			break
	if check == True:
		print('YES')
	else:
		print('NO')


for i in range(int(input())):
	(n, m) = list(map(int, input().split()))
	grid = [list(input()) for j in range(n)]
	flag = 1
	for i in range(n - 1):
		for j in range(m - 1):
			if grid[i][j] in ['0', '.'] and grid[i + 1][j] in ['0', '.'] and (grid[i][j + 1] in ['0', '.']) and (grid[i + 1][j + 1] in ['0', '.']):
				(grid[i][j], grid[i + 1][j], grid[i][j + 1], grid[i + 1][j + 1]) = ('0', '0', '0', '0')
	for i in range(n):
		for j in range(m):
			if grid[i][j] == '.':
				flag = 0
				break
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
jiggly = []
for x in range(t):
	(r, c) = input().split()
	(r, c) = (int(r), int(c))
	M = []
	y = []
	for i in range(r):
		M.append(input())
		for j in range(c):
			y.append(M[i][j])
		M[i] = y
		y = []
	for i in range(r - 1):
		for j in range(c - 1):
			if not (M[i][j] == '#' or M[i + 1][j] == '#' or M[i][j + 1] == '#' or (M[i + 1][j + 1] == '#')):
				(M[i][j], M[i + 1][j], M[i][j + 1], M[i + 1][j + 1]) = ('c', 'c', 'c', 'c')
	flag = 'YES'
	for i in range(r):
		for j in range(c):
			if not (M[i][j] == 'c' or M[i][j] == '#'):
				flag = 'NO'
	jiggly.append(flag)
for i in range(len(jiggly)):
	print(jiggly[i])


def main():
	(n, m) = map(int, input().split())
	arr = []
	for i in range(n):
		arr.append(list(input()))
	for i in range(n - 1):
		for j in range(m - 1):
			if arr[i][j] != '#' and arr[i][j + 1] != '#' and (arr[i + 1][j] != '#') and (arr[i + 1][j + 1] != '#'):
				arr[i][j] = 'c'
				arr[i][j + 1] = 'c'
				arr[i + 1][j] = 'c'
				arr[i + 1][j + 1] = 'c'
	for i in range(n):
		for j in range(m):
			if arr[i][j] == '.':
				print('NO')
				return
	print('YES')
	return
for _ in range(int(input())):
	main()


t = int(input())
for i in range(t):
	(n, m) = list(map(int, input().split()))
	g = []
	f = 0
	for i in range(n):
		r = list(input())
		g.append(r)
	for i in range(n):
		for j in range(m):
			if g[i][j] == '.':
				g[i][j] = 0
			elif g[i][j] == '#':
				g[i][j] = 1
	for i in range(n - 1):
		for j in range(m - 1):
			if (g[i][j] == 0 or g[i][j] == -1) and (g[i][j + 1] == 0 or g[i][j + 1] == -1) and (g[i + 1][j] == 0 or g[i + 1][j] == -1) and (g[i + 1][j + 1] == 0 or g[i + 1][j + 1] == -1):
				g[i][j] = -1
				g[i][j + 1] = -1
				g[i + 1][j] = -1
				g[i + 1][j + 1] = -1
	for i in range(n):
		for j in range(m):
			if g[i][j] == 0:
				f = 1
				break
		if f == 1:
			break
	if f == 1:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	arr = []
	fl = 0
	for i in range(n):
		arr.append(list(input()))
	for i in range(n - 1):
		for j in range(m - 1):
			if arr[i][j] == '0' or arr[i][j] == '.':
				if (arr[i + 1][j] == '0' or arr[i + 1][j] == '.') and (arr[i + 1][j + 1] == '0' or arr[i + 1][j + 1] == '.') and (arr[i][j + 1] == '.' or arr[i][j + 1] == '0'):
					arr[i + 1][j] = '0'
					arr[i + 1][j + 1] = '0'
					arr[i][j + 1] = '0'
					arr[i][j] = '0'
			else:
				continue
	for i in range(n):
		for j in range(m):
			if arr[i][j] == '.':
				fl = 1
				break
		if fl:
			break
	if fl:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(list(input()))
	for i in range(n - 1):
		for j in range(m - 1):
			if l[i][j] != '#' and l[i][j + 1] != '#' and (l[i + 1][j] != '#') and (l[i + 1][j + 1] != '#'):
				l[i][j] = '1'
				l[i + 1][j] = '1'
				l[i][j + 1] = '1'
				l[i + 1][j + 1] = '1'
	ans = 1
	for i in l:
		for j in i:
			if j == '.':
				ans = 0
				break
		if ans == 0:
			break
	if ans == 1:
		print('YES')
	else:
		print('NO')


def solve(mat, n, m):
	t = [mat[1][0], mat[0][1], mat[1][1]]
	if '#' in t and mat[0][0] == '.':
		return 'NO'
	t = [mat[1][m - 1], mat[0][m - 2], mat[1][m - 2]]
	if '#' in t and mat[0][m - 1] == '.':
		return 'NO'
	t = [mat[n - 2][0], mat[n - 1][1], mat[n - 2][1]]
	if '#' in t and mat[n - 1][0] == '.':
		return 'NO'
	t = [mat[n - 2][m - 1], mat[n - 1][m - 2], mat[n - 2][m - 2]]
	if '#' in t and mat[n - 1][m - 1] == '.':
		return 'NO'
	for j in range(1, m - 1):
		if mat[0][j] == '.':
			t = []
			t.append([mat[1][j], mat[1][j + 1], mat[0][j + 1]])
			t.append([mat[1][j], mat[0][j - 1], mat[1][j - 1]])
			if '#' in t[0] and '#' in t[1]:
				return 'NO'
		if mat[n - 1][j] == '.':
			t = []
			t.append([mat[n - 2][j], mat[n - 2][j + 1], mat[n - 1][j + 1]])
			t.append([mat[n - 2][j], mat[n - 1][j - 1], mat[n - 2][j - 1]])
			if '#' in t[0] and '#' in t[1]:
				return 'NO'
	for i in range(1, n - 1):
		if mat[i][0] == '.':
			t = []
			t.append([mat[i + 1][1], mat[i + 1][0], mat[i][1]])
			t.append([mat[i - 1][1], mat[i][1], mat[i - 1][0]])
			if '#' in t[0] and '#' in t[1]:
				return 'NO'
		if mat[i][m - 1] == '.':
			t = []
			t.append([mat[i + 1][m - 2], mat[i + 1][m - 1], mat[i][m - 2]])
			t.append([mat[i - 1][m - 2], mat[i][m - 2], mat[i - 1][m - 1]])
			if '#' in t[0] and '#' in t[1]:
				return 'NO'
	for i in range(1, n - 1):
		for j in range(1, m - 1):
			if mat[i][j] == '.':
				t = []
				t.append([mat[i + 1][j], mat[i + 1][j + 1], mat[i][j + 1]])
				t.append([mat[i - 1][j], mat[i][j - 1], mat[i - 1][j - 1]])
				t.append([mat[i + 1][j], mat[i][j - 1], mat[i + 1][j - 1]])
				t.append([mat[i - 1][j], mat[i - 1][j + 1], mat[i][j + 1]])
				if '#' in t[0] and '#' in t[1] and ('#' in t[2]) and ('#' in t[3]):
					return 'NO'
	return 'YES'
for test in range(int(input())):
	d = [int(j) for j in input().split()]
	mat = []
	for i in range(d[0]):
		mat.append(list(input()))
	print(solve(mat, d[0], d[1]))


t = int(input())
for fdi in range(t):
	(n, m) = [int(x) for x in input().split()]
	a = []
	a.append(['#'] * (m + 2))
	c = 0
	for i in range(n):
		k = list(input())
		c += k.count('#')
		k = ['#'] + k + ['#']
		a.append(k)
	a.append(['#'] * (m + 2))
	if c == 0:
		print('YES')
		continue
	ans = 0
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			if a[i][j] == '#':
				te = 1
				continue
			if a[i][j - 1] == '.' and a[i - 1][j] == '.' and (a[i - 1][j - 1] == '.'):
				te = 1
			elif a[i - 1][j] == '.' and a[i][j + 1] == '.' and (a[i - 1][j + 1] == '.'):
				te = 1
			elif a[i][j - 1] == '.' and a[i + 1][j] == '.' and (a[i + 1][j - 1] == '.'):
				te = 1
			elif a[i][j + 1] == '.' and a[i + 1][j] == '.' and (a[i + 1][j + 1] == '.'):
				te = 1
			else:
				te = 0
				break
		if te == 0:
			ans = 1
			break
	if ans == 0:
		print('YES')
	else:
		print('NO')


t = int(input())
for _ in range(t):
	(n, m) = input().strip().split(' ')
	n = int(n)
	m = int(m)
	b = []
	for i in range(n):
		b.append(input())
	a = [[0 for j in range(m)] for i in range(n)]
	for i in range(n):
		for j in range(m):
			if b[i][j] == '#':
				a[i][j] = -1
	for i in range(n - 1):
		for j in range(m - 1):
			if a[i][j] != -1 and a[i][j + 1] != -1 and (a[i + 1][j] != -1) and (a[i + 1][j + 1] != -1):
				a[i][j] = a[i][j + 1] = a[i + 1][j] = a[i + 1][j + 1] = 1
	flag = 0
	for i in range(n):
		for j in range(m):
			if a[i][j] == 0:
				flag = 1
				break
		if flag == 1:
			break
	if flag == 1:
		print('NO')
	else:
		print('YES')


def paint(m, a, b):
	for i in range(0, a - 1):
		for j in range(0, b - 1):
			l = [m[i][j], m[i + 1][j + 1], m[i + 1][j], m[i][j + 1]]
			if l.count('#') == 0:
				m[i][j] = m[i + 1][j + 1] = m[i + 1][j] = m[i][j + 1] = 1
	ch = 0
	c1 = 0
	for f in m:
		ch = ch + f.count('#')
		c1 = c1 + f.count(1)
	if ch + c1 == a * b:
		return 'YES'
	else:
		return 'NO'
n = input()
n = int(n)
for i in range(n):
	nm = input().split()
	matrix = [list(input().strip()) for x in range(int(nm[0]))]
	print(paint(matrix, int(nm[0]), int(nm[1])))


def colour(grid, n, m):
	for r in range(n - 1):
		for c in range(m - 1):
			if grid[r][c] != '#' and grid[r + 1][c] != '#' and (grid[r][c + 1] != '#') and (grid[r + 1][c + 1] != '#'):
				grid[r][c] = 1
				grid[r + 1][c] = 1
				grid[r][c + 1] = 1
				grid[r + 1][c + 1] = 1
	return grid
for t in range(int(input())):
	(n, m) = map(int, input().split())
	grid = []
	flag = 1
	for i in range(n):
		grid.append(list(input()))
	grid = colour(grid, n, m)
	for r in range(n):
		for c in range(m):
			if grid[r][c] == '.':
				flag = 0
				break
	if flag:
		print('YES')
	else:
		print('NO')


t = int(input())
while t:
	inp = list(map(int, input().split()))
	n = inp[0]
	m = inp[1]
	arr = []
	for i in range(0, n):
		inp2 = input()
		arr.append(inp2[0:m])
	b = [[0] * m for i in range(n)]
	for i in range(0, n):
		for j in range(0, m):
			if arr[i][j] == '#':
				b[i][j] = 1
			elif i + 1 < n and j + 1 < m and (arr[i + 1][j] != '#') and (arr[i + 1][j + 1] != '#') and (arr[i][j + 1] != '#'):
				b[i][j] = 1
				b[i][j + 1] = 1
				b[i + 1][j] = 1
				b[i + 1][j + 1] = 1
	z = 1
	for i in range(0, n):
		for j in range(0, m):
			if not b[i][j]:
				print('NO')
				z = 0
				break
		if not z:
			break
	if z:
		print('YES')
	t -= 1


t = int(input())
for i in range(t):
	(n, m) = input().split(' ')
	n = int(n)
	m = int(m)
	grid = []
	for i in range(n):
		grid.append(list(input()))
	temp = [[0 for x in range(m)] for y in range(n)]
	for i in range(n):
		for j in range(m):
			if grid[i][j] == '.':
				temp[i][j] = 0
			else:
				temp[i][j] = -1
	for i in range(n - 1):
		for j in range(m - 1):
			if grid[i][j] == '#' or grid[i + 1][j] == '#' or grid[i][j + 1] == '#' or (grid[i + 1][j + 1] == '#'):
				continue
			else:
				temp[i][j] += 1
				temp[i + 1][j] += 1
				temp[i][j + 1] += 1
				temp[i + 1][j + 1] += 1
	flag = 0
	for i in range(n):
		for j in range(m):
			if temp[i][j] == 0:
				print('NO')
				flag = 1
				break
		if flag == 1:
			break
	if flag == 0:
		print('YES')


t = int(input())
for i in range(0, t):
	(n, m) = [int(x) for x in input().split()]
	mat = [0] * n
	for i in range(0, n):
		mat[i] = input()
	arr = []
	arr2 = []
	if n * m < 4:
		print('NO')
		continue
	for i in range(0, len(mat)):
		for j in range(0, len(mat[i])):
			if mat[i][j] == '#':
				if i + 1 <= n - 1 and mat[i + 1][j] == '.':
					arr.append(i + 1)
					arr2.append(j)
				if i + 1 <= n - 1 and j + 1 <= m - 1 and (mat[i + 1][j + 1] == '.'):
					arr.append(i + 1)
					arr2.append(j + 1)
				if i + 1 <= n - 1 and j - 1 >= 0 and (mat[i + 1][j - 1] == '.'):
					arr.append(i + 1)
					arr2.append(j - 1)
				if j + 1 <= m - 1 and mat[i][j + 1] == '.':
					arr.append(i)
					arr2.append(j + 1)
				if j - 1 >= 0 and mat[i][j - 1] == '.':
					arr.append(i)
					arr2.append(j - 1)
				if i - 1 >= 0 and mat[i - 1][j] == '.':
					arr.append(i - 1)
					arr2.append(j)
				if i - 1 >= 0 and j - 1 >= 0 and (mat[i - 1][j - 1] == '.'):
					arr.append(i - 1)
					arr2.append(j - 1)
				if i - 1 >= 0 and j + 1 <= m - 1 and (mat[i - 1][j + 1] == '.'):
					arr.append(i - 1)
					arr2.append(j + 1)
	case = 0
	if len(arr) == 0:
		if mat[0][0] == '.':
			print('YES')
		else:
			print('NO')
		continue
	for i in range(0, len(arr)):
		count = 1
		p = arr[i]
		r = arr2[i]
		if (r - 1 >= 0 and mat[p][r - 1] == '.') and (r - 1 >= 0 and p - 1 >= 0 and (mat[p - 1][r - 1] == '.')) and (p - 1 >= 0 and mat[p - 1][r] == '.'):
			count += 3
		if (r + 1 <= m - 1 and mat[p][r + 1] == '.') and (r + 1 <= m - 1 and p + 1 <= n - 1 and (mat[p + 1][r + 1] == '.')) and (p + 1 <= n + 1 and mat[p + 1][r] == '.'):
			count += 3
		if (p - 1 >= 0 and mat[p - 1][r] == '.') and (p - 1 >= 0 and r + 1 <= m - 1 and (mat[p - 1][r + 1] == '.')) and (r + 1 <= m - 1 and mat[p][r + 1] == '.'):
			count += 3
		if (p + 1 <= n - 1 and mat[p + 1][r] == '.') and (r - 1 >= 0 and p + 1 <= n - 1 and (mat[p + 1][r - 1] == '.')) and (r - 1 >= 0 and mat[p][r - 1] == '.'):
			count += 3
		if count >= 4:
			case = 1
		else:
			case = 0
			break
	if case == 1:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(N, M) = map(int, input().split())
	temp = []
	visited = []
	for x in range(N):
		line = input()
		temp.append(line)
		visited.append([0] * M)
	for i in range(N):
		for j in range(M):
			if temp[i][j] is '.':
				if i + 1 < N and j + 1 < M:
					if temp[i][j] is '.' and temp[i + 1][j] is '.' and (temp[i][j + 1] is '.') and (temp[i + 1][j + 1] is '.'):
						visited[i + 1][j + 1] = 1
						visited[i][j] = 1
						visited[i + 1][j] = 1
						visited[i][j + 1] = 1
	check = True
	for i in range(N):
		for j in range(M):
			if temp[i][j] is '.' and visited[i][j] is 0:
				check = False
				break
	print('YES' if check else 'NO')


T = int(input())
for _ in range(T):
	lt = []
	c = 0
	c1 = 0
	(N, M) = map(int, input().split())
	for k in range(N):
		s = input()
		lt1 = list(s)
		lt.append(lt1)
	for i in range(N):
		for j in range(M):
			if lt[i][j] == '.':
				c1 += 1
				f = 0
				if i + 1 < N and j + 1 < M:
					if lt[i + 1][j] == '.' and lt[i][j + 1] == '.' and (lt[i + 1][j + 1] == '.'):
						c += 1
						f = 1
				if i - 1 >= 0 and j + 1 < M and (f == 0):
					if lt[i - 1][j] == '.' and lt[i][j + 1] == '.' and (lt[i - 1][j + 1] == '.'):
						c += 1
						f = 1
				if i - 1 >= 0 and j - 1 >= 0 and (f == 0):
					if lt[i - 1][j] == '.' and lt[i][j - 1] == '.' and (lt[i - 1][j - 1] == '.'):
						c += 1
						f = 1
				if i + 1 < N and j - 1 >= 0 and (f == 0):
					if lt[i + 1][j] == '.' and lt[i][j - 1] == '.' and (lt[i + 1][j - 1] == '.'):
						c += 1
						f = 1
	if c1 == c:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	grid = []
	for l in range(n):
		row = input()
		grid.append(list(row))
	zeros = [[0] * m for _ in range(n)]
	ans = [[0] * m for _ in range(n)]
	for i in range(n):
		for j in range(m):
			if grid[i][j] == '.':
				ans[i][j] = 1
			if i <= n - 2 and j <= m - 2:
				if grid[i][j] == '.':
					if grid[i + 1][j] == '.' and grid[i][j + 1] == '.' and (grid[i + 1][j + 1] == '.'):
						zeros[i][j] = 1
						zeros[i + 1][j] = 1
						zeros[i][j + 1] = 1
						zeros[i + 1][j + 1] = 1
	if ans == zeros:
		print('YES')
	else:
		print('NO')


def createBorder(A, c):
	(H, W) = (len(A), len(A[0]))
	return [c * (W + 2)] + [c + row + c for row in A] + [c * (W + 2)]

def testGrid(A):
	for R in range(1, len(A)):
		for C in range(1, len(A[0])):
			if A[R][C] != '.':
				continue
			X = [A[cellR][cellC] for (cellR, cellC) in [(R - 1, C - 1), (R - 1, C), (R - 1, C + 1), (R, C - 1), (R, C), (R, C + 1), (R + 1, C - 1), (R + 1, C), (R + 1, C + 1)]]
			if all((X[i] == '.' for i in (0, 1, 3, 4))):
				continue
			if all((X[i] == '.' for i in (1, 2, 4, 5))):
				continue
			if all((X[i] == '.' for i in (3, 4, 6, 7))):
				continue
			if all((X[i] == '.' for i in (4, 5, 7, 8))):
				continue
			return False
	return True
for _ in range(int(input())):
	(H, W) = [int(x) for x in input().split()]
	A = [input() for row in range(H)]
	A = createBorder(A, '#')
	print(['NO', 'YES'][testGrid(A)])


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	seen = {}
	for i in range(n + 2):
		for j in range(m + 2):
			if i == 0 or i == n + 1:
				seen[i - 1, j - 1] = -1
			elif j == 0 or j == m + 1:
				seen[i - 1, j - 1] = -1
			else:
				seen[i - 1, j - 1] = 0
	for i in range(n):
		st = input()
		for (j, it) in enumerate(st):
			if it == '#':
				seen[i, j] = 1
	flg = False
	for i in range(n):
		done = False
		for j in range(m):
			if seen[i, j] == 0:
				if seen[i - 1, j - 1] == 0 and seen[i - 1, j] == 0 and (seen[i, j - 1] == 0):
					continue
				elif seen[i - 1, j + 1] == 0 and seen[i - 1, j] == 0 and (seen[i, j + 1] == 0):
					continue
				elif seen[i + 1, j - 1] == 0 and seen[i + 1, j] == 0 and (seen[i, j - 1] == 0):
					continue
				elif seen[i + 1, j + 1] == 0 and seen[i + 1, j] == 0 and (seen[i, j + 1] == 0):
					continue
				else:
					print('NO')
					done = True
					break
		if done:
			flg = True
			break
	if not flg:
		print('YES')


T = int(input())
for _ in range(T):
	(N, M) = map(int, input().split())
	l = []
	for _ in range(N):
		p = list(input())
		l.append(p)
	for i in range(len(l) - 1):
		for j in range(M - 1):
			if l[i][j] != '#' and l[i][j + 1] != '#' and (l[i + 1][j] != '#') and (l[i + 1][j + 1] != '#'):
				l[i][j] = 'f'
				l[i + 1][j] = 'f'
				l[i][j + 1] = 'f'
				l[i + 1][j + 1] = 'f'
	k = 0
	for i in l:
		if '.' in i:
			print('NO')
			k = 1
			break
	if k == 0:
		print('YES')


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	l = []
	val = 0
	for j in range(n):
		l.append(list(input()))
	for j in range(n):
		f = 0
		for k in range(m):
			if l[j][k] == '#':
				continue
			if k + 1 < m and j + 1 < n and (l[j][k + 1] == '.') and (l[j + 1][k + 1] == '.') and (l[j + 1][k] == '.'):
				f = 0
			elif k - 1 >= 0 and j + 1 < n and (l[j][k - 1] == '.') and (l[j + 1][k] == '.') and (l[j + 1][k - 1] == '.'):
				f = 0
			elif k + 1 < m and j - 1 >= 0 and (l[j - 1][k] == '.') and (l[j - 1][k + 1] == '.') and (l[j][k + 1] == '.'):
				f = 0
			elif k - 1 >= 0 and j - 1 >= 0 and (l[j - 1][k - 1] == '.') and (l[j - 1][k] == '.') and (l[j][k - 1] == '.'):
				f = 0
			else:
				f = 1
			if f == 0:
				continue
			else:
				f = 0
				val = 1
				print('NO')
				break
		if val == 1:
			break
	if val == 0:
		print('YES')


def isDot(c):
	return c == '.' or c == 'x'

def draw(board, N, M, r, c):
	cell = board[r][c]
	if cell == 'x' or cell == '#':
		return True
	if c + 1 < M and isDot(board[r][c + 1]):
		if r + 1 < N and isDot(board[r + 1][c]) and isDot(board[r + 1][c + 1]):
			board[r][c] = 'x'
			return True
		elif r > 0 and isDot(board[r - 1][c]) and isDot(board[r - 1][c + 1]):
			board[r][c] = 'x'
			return True
	if c > 0 and isDot(board[r][c - 1]):
		if r + 1 < N and isDot(board[r + 1][c]) and isDot(board[r + 1][c - 1]):
			board[r][c] = 'x'
			return True
		elif r > 0 and isDot(board[r - 1][c]) and isDot(board[r - 1][c - 1]):
			board[r][c] = 'x'
			return True
	return False
T = int(input())
for x in range(T):
	(n, m) = map(int, input().split(' '))
	board = []
	answer = 'YES'
	for row in range(n):
		cols = list(input())
		board.append(cols)
	for (row_no, row) in enumerate(board):
		if answer == 'NO':
			break
		for (col_no, cell) in enumerate(row):
			if answer == 'YES' and draw(board, n, m, row_no, col_no):
				pass
			else:
				answer = 'NO'
				break
	print(answer)


try:
	t = int(input())
	while t:
		(n, m) = map(int, input().split())
		l = []
		n1 = n
		while n:
			nl = list(map(str, input().split()))
			s = nl[0]
			s = list(s)
			l.append(s)
			n -= 1
		for i in range(n1 - 1):
			for j in range(m - 1):
				if (l[i][j] == '.' or l[i][j] == 1) and (l[i][j + 1] == '.' or l[i][j + 1] == 1):
					if (l[i + 1][j] == '.' or l[i + 1][j] == 1) and (l[i + 1][j + 1] == '.' or l[i + 1][j + 1] == 1):
						l[i][j] = l[i + 1][j] = l[i + 1][j + 1] = l[i][j + 1] = 1
					else:
						continue
				else:
					continue
		for _ in l:
			f = _.count('.')
			if f > 0:
				print('NO')
				break
			else:
				continue
		else:
			print('YES')
		t -= 1
except:
	pass


test = int(input())
for i in range(test):
	(rows, column) = map(int, input().split())
	mat = []
	flag = True
	for i in range(rows):
		mat.append(list(input()))
	for i in range(rows - 1):
		for j in range(column - 1):
			if mat[i][j] != '#' and mat[i + 1][j] != '#' and (mat[i][j + 1] != '#') and (mat[i + 1][j + 1] != '#'):
				mat[i][j] = '1'
				mat[i + 1][j] = '1'
				mat[i][j + 1] = '1'
				mat[i + 1][j + 1] = '1'
	for i in range(rows):
		for j in range(column):
			if mat[i][j] == '.':
				flag = False
				break
	if flag:
		print('YES')
	else:
		print('NO')


for _ in range(int(input())):
	(N, M) = input().strip().split(' ')
	N = int(N)
	M = int(M)
	T = []
	for _ in range(N):
		T.append(input())
	count = 0
	for i in range(N):
		for j in range(M):
			if T[i][j] == '.':
				if i != 0 and j != 0 and (i != N - 1) and (j != M - 1):
					if T[i][j + 1] == '.' and T[i + 1][j] == '.' and (T[i + 1][j + 1] == '.') or (T[i][j - 1] == '.' and T[i + 1][j] == '.' and (T[i + 1][j - 1] == '.')) or (T[i][j + 1] == '.' and T[i - 1][j] == '.' and (T[i - 1][j + 1] == '.')) or (T[i][j - 1] == '.' and T[i - 1][j] == '.' and (T[i - 1][j - 1] == '.')):
						continue
					else:
						count += 1
						break
				if i == 0 and j != 0 and (i != N - 1) and (j != M - 1):
					if T[i][j + 1] == '.' and T[i + 1][j] == '.' and (T[i + 1][j + 1] == '.') or (T[i][j - 1] == '.' and T[i + 1][j] == '.' and (T[i + 1][j - 1] == '.')):
						continue
					else:
						count += 1
						break
				if i != 0 and j != 0 and (i == N - 1) and (j != M - 1):
					if T[i][j + 1] == '.' and T[i - 1][j] == '.' and (T[i - 1][j + 1] == '.') or (T[i][j - 1] == '.' and T[i - 1][j] == '.' and (T[i - 1][j - 1] == '.')):
						continue
					else:
						count += 1
						break
				if i != 0 and j == 0 and (i != N - 1) and (j != M - 1):
					if T[i][j + 1] == '.' and T[i + 1][j] == '.' and (T[i + 1][j + 1] == '.') or (T[i][j + 1] == '.' and T[i - 1][j] == '.' and (T[i - 1][j + 1] == '.')):
						continue
					else:
						count += 1
						break
				if i != 0 and j != 0 and (i != N - 1) and (j == M - 1):
					if T[i][j - 1] == '.' and T[i + 1][j] == '.' and (T[i + 1][j - 1] == '.') or (T[i][j - 1] == '.' and T[i - 1][j] == '.' and (T[i - 1][j - 1] == '.')):
						continue
					else:
						count += 1
						break
				if i == 0 and j == 0 and (i != N - 1) and (j != M - 1):
					if T[i][j + 1] == '.' and T[i + 1][j] == '.' and (T[i + 1][j + 1] == '.'):
						continue
					else:
						count += 1
						break
				if i == 0 and j != 0 and (i != N - 1) and (j == M - 1):
					if T[i][j - 1] == '.' and T[i + 1][j] == '.' and (T[i + 1][j - 1] == '.'):
						continue
					else:
						count += 1
						break
				if i != 0 and j == 0 and (i == N - 1) and (j != M - 1):
					if T[i][j + 1] == '.' and T[i - 1][j] == '.' and (T[i - 1][j + 1] == '.'):
						continue
					else:
						count += 1
						break
				if i != 0 and j != 0 and (i == N - 1) and (j == M - 1):
					if T[i][j - 1] == '.' and T[i - 1][j] == '.' and (T[i - 1][j - 1] == '.'):
						continue
					else:
						count += 1
						break
	if count > 0:
		print('NO')
	else:
		print('YES')


for _ in range(int(input())):
	(n, m) = [int(d) for d in input().split()]
	a = []
	s = []
	i = [0 for x in range(m)]
	for x in range(n):
		s.append(input())
		a.append([0 for x in range(m)])
	for x in range(n - 1):
		for y in range(m - 1):
			if s[x][y] == '.' and s[x][y + 1] == '.' and (s[x + 1][y] == '.') and (s[x + 1][y + 1] == '.'):
				a[x][y] = 1
				a[x][y + 1] = 1
				a[x + 1][y] = 1
				a[x + 1][y + 1] = 1
	l = True
	for x in range(n):
		for y in range(m):
			if s[x][y] == '.' and a[x][y] == 0:
				l = False
	if l:
		print('YES')
	else:
		print('NO')


for t in range(int(input())):
	(n, m) = map(int, input().split(' '))
	ar = []
	for i in range(n):
		ar.append(list(input()))
	for i in range(n - 1):
		for j in range(m - 1):
			if ar[i][j] != '#' and ar[i][j + 1] != '#' and (ar[i + 1][j] != '#') and (ar[i + 1][j + 1] != '#'):
				ar[i][j] = ar[i][j + 1] = ar[i + 1][j] = ar[i + 1][j + 1] = '-'
	f = 0
	for i in range(n):
		for j in range(m):
			if ar[i][j] == '.':
				f = 1
				break
	if f == 0:
		print('YES')
	else:
		print('NO')


T = int(input())
for _ in range(T):
	(N, M) = map(int, input().split())
	a = []
	for _ in range(N):
		a.append(list(input()))
	flag = 1
	for i in range(N):
		for j in range(M):
			if a[i][j] == '#':
				continue
			if i == 0 and j == 0:
				if '#' in (a[i][j + 1], a[i + 1][j + 1], a[i + 1][j]):
					flag = 0
					break
			elif i == 0 and j == M - 1:
				if '#' in (a[i][j - 1], a[i + 1][j - 1], a[i + 1][j]):
					flag = 0
					break
			elif i == 0:
				if '#' in (a[i][j + 1], a[i + 1][j + 1], a[i + 1][j]) and '#' in (a[i][j - 1], a[i + 1][j - 1], a[i + 1][j]):
					flag = 0
					break
			elif i == N - 1 and j == 0:
				if '#' in (a[i][j + 1], a[i - 1][j + 1], a[i - 1][j]):
					flag = 0
					break
			elif j == 0:
				if '#' in (a[i][j + 1], a[i + 1][j + 1], a[i + 1][j]) and '#' in (a[i][j + 1], a[i - 1][j + 1], a[i - 1][j]):
					flag = 0
					break
			elif i == N - 1 and j == M - 1:
				if '#' in (a[i][j - 1], a[i - 1][j - 1], a[i - 1][j]):
					flag = 0
					break
			elif i == N - 1:
				if '#' in (a[i][j + 1], a[i - 1][j + 1], a[i - 1][j]) and '#' in (a[i][j - 1], a[i - 1][j - 1], a[i - 1][j]):
					flag = 0
					break
			elif j == M - 1:
				if '#' in (a[i][j - 1], a[i + 1][j - 1], a[i + 1][j]) and '#' in (a[i][j - 1], a[i - 1][j - 1], a[i - 1][j]):
					flag = 0
					break
			elif '#' in (a[i][j + 1], a[i - 1][j + 1], a[i - 1][j]) and '#' in (a[i][j - 1], a[i - 1][j - 1], a[i - 1][j]) and ('#' in (a[i][j + 1], a[i + 1][j + 1], a[i + 1][j])) and ('#' in (a[i][j - 1], a[i + 1][j - 1], a[i + 1][j])):
				flag = 0
				break
		if flag == 0:
			break
	if flag == 0:
		print('NO')
	else:
		print('YES')