You are given a picture consisting of $n$ rows and $m$ columns. Rows are numbered from $1$ to $n$ from the top to the bottom, columns are numbered from $1$ to $m$ from the left to the right. Each cell is painted either black or white. 

You think that this picture is not interesting enough. You consider a picture to be interesting if there is at least one cross in it. A cross is represented by a pair of numbers $x$ and $y$, where $1 \le x \le n$ and $1 \le y \le m$, such that all cells in row $x$ and all cells in column $y$ are painted black.

For examples, each of these pictures contain crosses:

 [Image] 

The fourth picture contains 4 crosses: at $(1, 3)$, $(1, 5)$, $(3, 3)$ and $(3, 5)$.

Following images don't contain crosses:

 [Image] 

You have a brush and a can of black paint, so you can make this picture interesting. Each minute you may choose a white cell and paint it black.

What is the minimum number of minutes you have to spend so the resulting picture contains at least one cross?

You are also asked to answer multiple independent queries.


-----Input-----

The first line contains an integer $q$ ($1 \le q \le 5 \cdot 10^4$) — the number of queries.

The first line of each query contains two integers $n$ and $m$ ($1 \le n, m \le 5 \cdot 10^4$, $n \cdot m \le 4 \cdot 10^5$) — the number of rows and the number of columns in the picture.

Each of the next $n$ lines contains $m$ characters — '.' if the cell is painted white and '*' if the cell is painted black.

It is guaranteed that $\sum n \le 5 \cdot 10^4$ and $\sum n \cdot m \le 4 \cdot 10^5$.


-----Output-----

Print $q$ lines, the $i$-th line should contain a single integer — the answer to the $i$-th query, which is the minimum number of minutes you have to spend so the resulting picture contains at least one cross.


-----Example-----
Input
9
5 5
..*..
..*..
*****
..*..
..*..
3 4
****
.*..
.*..
4 3
***
*..
*..
*..
5 5
*****
*.*.*
*****
..*.*
..***
1 4
****
5 5
.....
..*..
.***.
..*..
.....
5 3
...
.*.
.*.
***
.*.
3 3
.*.
*.*
.*.
4 4
*.**
....
*.**
*.**

Output
0
0
0
0
0
4
1
1
2



-----Note-----

The example contains all the pictures from above in the same order.

The first 5 pictures already contain a cross, thus you don't have to paint anything.

You can paint $(1, 3)$, $(3, 1)$, $(5, 3)$ and $(3, 5)$ on the $6$-th picture to get a cross in $(3, 3)$. That'll take you $4$ minutes.

You can paint $(1, 2)$ on the $7$-th picture to get a cross in $(4, 2)$.

You can paint $(2, 2)$ on the $8$-th picture to get a cross in $(2, 2)$. You can, for example, paint $(1, 3)$, $(3, 1)$ and $(3, 3)$ to get a cross in $(3, 3)$ but that will take you $3$ minutes instead of $1$.

There are 9 possible crosses you can get in minimum time on the $9$-th picture. One of them is in $(1, 1)$: paint $(1, 2)$ and $(2, 1)$.

Difficulty: EASY
Tags: Implementation

Starter code:

Solutions:
import sys
z = int(input())
for _ in range(z):
	ans = 99999999
	(n, m) = [int(i) for i in sys.stdin.readline().split()]
	df = []
	for _ in range(n):
		df.append(sys.stdin.readline())
	l = [df[i].count('.') for i in range(n)]
	df2 = list(map(list, zip(*df)))
	w = [df2[i].count('.') for i in range(m)]
	for i in range(n):
		ans1 = l[i]
		x = w.copy()
		for j in range(m):
			if df[i][j] == '.':
				x[j] -= 1
		ans2 = min(x)
		ans = min(ans, ans1 + ans2)
	print(ans)


from sys import stdin, stdout

def main():
	t = int(stdin.readline())
	for _ in range(t):
		(m, n) = map(int, stdin.readline().split())
		mat = []
		for _ in range(m):
			mat.append(stdin.readline())
		row = [0] * m
		col = [0] * n
		for i in range(m):
			for j in range(n):
				if mat[i][j] == '*':
					row[i] += 1
					col[j] += 1
		max_row = max(row)
		max_col = max(col)
		cr = []
		for i in range(m):
			if row[i] == max_row:
				cr.append(i)
		cc = []
		for i in range(n):
			if col[i] == max_col:
				cc.append(i)
		ans = m + n - 1
		for i in cr:
			for j in cc:
				if mat[i][j] == '.':
					ans = min(ans, m + n - (row[i] + col[j] + 1))
				else:
					ans = min(ans, m + n - (row[i] + col[j]))
		stdout.write(str(ans))
		stdout.write('\n')
main()


from fractions import gcd
import math

def inverse(a):
	return pow(a, mod - 2, mod)

def usearch(x, a):
	lft = 0
	rgt = len(a) + 1
	while rgt - lft > 1:
		mid = (rgt + lft) // 2
		if a[mid] <= x:
			lft = mid
		else:
			rgt = mid
	return lft

def main():
	q = int(input())
	for i in range(q):
		(n, m) = list(map(int, input().split()))
		a = [input() for i in range(n)]
		h = 0
		h_a = []
		for i in range(m):
			tmp = 0
			for j in range(n):
				if a[j][i] == '*':
					tmp += 1
			if h < tmp:
				h = tmp
				h_a = [i]
			if h == tmp:
				h_a.append(i)
		w = 0
		w_a = []
		for i in range(n):
			tmp = len([i for i in a[i] if i == '*'])
			if w < tmp:
				w = tmp
				w_a = [i]
			if w == tmp:
				w_a.append(i)
		flag = 0
		for i in h_a:
			for j in w_a:
				if a[j][i] == '.':
					flag = 1
					break
		print(n + m - h - w - flag)
main()


def go():
	(n, m) = [int(i) for i in input().split(' ')]
	matrix = []
	line = []
	column = []
	for i in range(n):
		x = 0
		matrix.append([])
		for j in input():
			w = 0
			if j == '.':
				w = 1
				x += 1
			matrix[i].append(w)
		line.append(x)
	for j in range(m):
		x = 0
		for i in range(n):
			x += matrix[i][j]
		column.append(x)
	o = float('inf')
	for i in range(n):
		for j in range(m):
			x = line[i] + column[j]
			if matrix[i][j] == 1:
				x -= 1
			o = min(o, x)
	return o
o = ''
q = int(input())
for _ in range(q):
	o += f'{go()}\n'
print(o)


Q = int(input())
from copy import copy, deepcopy

def solve():
	[N, M] = list(map(int, input().split()))
	grid = []
	for _ in range(N):
		grid.append(list(input()))
	row_count = []
	column_count = []
	for row in grid:
		x = 0
		for g in row:
			if g == '*':
				x += 1
		row_count.append(x)
	for m in range(M):
		x = 0
		for n in range(N):
			if grid[n][m] == '*':
				x += 1
		column_count.append(x)
	ans = N * M
	for n in range(N):
		for m in range(M):
			ans_ = N + M - (row_count[n] + column_count[m])
			if grid[n][m] == '.':
				ans_ -= 1
			ans = min(ans, ans_)
	return ans
for _ in range(Q):
	print(solve())


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = []
	r = [0] * n
	for i in range(n):
		a.append(input())
		r[i] = a[i].count('.')
	c = [0] * m
	for i in range(m):
		co = 0
		for j in range(n):
			if a[j][i] == '.':
				co += 1
		c[i] = co
	mc = c[0]
	mr = r[0]
	ri = 0
	ci = 0
	for i in range(n):
		if r[i] < mr:
			mr = r[i]
			ri = i
	for i in range(m):
		if c[i] < mc:
			mc = c[i]
			ci = i
	minr = []
	minc = []
	for i in range(n):
		if r[i] == mr:
			minr.append([r[i], i])
	for i in range(m):
		if c[i] == mc:
			minc.append([c[i], i])
	ans = mr + mc
	f = 0
	for i in range(len(minr)):
		for j in range(len(minc)):
			if a[minr[i][1]][minc[j][1]] == '.':
				f = 1
				ans = ans - 1
				break
		if f == 1:
			break
	print(ans)


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	a = [input() for _ in range(n)]
	a_t = list(zip(*a))
	mx_1 = mx_2 = 0
	idx_1 = []
	idx_2 = []
	for (j, i) in enumerate(a):
		temp = i.count('*')
		if temp > mx_1:
			mx_1 = temp
			idx_1 = [j]
		elif temp == mx_1:
			idx_1.append(j)
	for (j, i) in enumerate(a_t):
		temp = i.count('*')
		if temp > mx_2:
			mx_2 = temp
			idx_2 = [j]
		elif temp == mx_2:
			idx_2.append(j)
	ans = 0
	for i in idx_1:
		for j in idx_2:
			if a[i][j] == '.':
				ans = -1
	print(n + m - mx_1 - mx_2 + ans)


from collections import Counter
for _ in range(int(input())):
	(x, y) = map(int, input().split())
	l = []
	row = []
	column = []
	for t in range(x):
		xc = list(input())
		zz = Counter(xc)
		row.append(zz['.'])
		l.append(xc)
	za = 0
	for i in range(y):
		for j in range(x):
			if l[j][i] == '.':
				za += 1
		column.append(za)
		za = 0
	ans = []
	for q in range(x):
		for w in range(y):
			r = row[q]
			c = column[w]
			if l[q][w] == '.':
				ans.append(r + c - 1)
			else:
				ans.append(r + c)
	print(min(ans))


a = int(input())
for i in range(a):
	(n, m) = list(map(int, input().split()))
	d = [[0] * m for i in range(n)]
	row = [0] * n
	col = [0] * m
	e = [input() for i in range(n)]
	for i in range(n):
		for j in range(m):
			if e[i][j] == '*':
				d[i][j] += 1
				row[i] += 1
				col[j] += 1
	mi = 1000000000000
	for i in range(n):
		for j in range(m):
			if n + m - 1 - (row[i] + col[j] - d[i][j]) < mi:
				mi = n + m - 1 - (row[i] + col[j] - d[i][j])
	print(mi)


def readInts():
	return [int(x) for x in input().split()]
T = int(input())
for t in range(T):
	[n, m] = readInts()
	countRow = [0 for i in range(n)]
	countCol = [0 for i in range(m)]
	grid = []
	for rowIndex in range(n):
		line = input()
		line = [ch == '*' for ch in line]
		grid.append(line)
		for (colIndex, isBlack) in enumerate(line):
			if isBlack:
				countRow[rowIndex] += 1
				countCol[colIndex] += 1
	result = n + m - 1
	for i in range(n):
		for j in range(m):
			totalBlack = countRow[i] + countCol[j]
			if grid[i][j]:
				totalBlack -= 1
			result = min(result, n + m - 1 - totalBlack)
	print(result)


q = int(input())
(inp, n, m, t) = (0, 0, 0, 0)
row = []
col = []
(rmx, cmx) = (0, 0)
dem = 0
kq = 0
for i in range(q):
	inp = list(map(int, input().split()))
	(n, m) = (inp[0], inp[1])
	kq = n + m - 1
	inp = []
	(rmx, cmx) = (0, 0)
	dem = 0
	row = []
	col = []
	t = input()
	inp.append(t)
	for k in range(m):
		if t[k] == '*':
			dem += 1
			col.append(1)
		else:
			col.append(0)
	row.append(dem)
	for j in range(1, n):
		t = input()
		inp.append(t)
		dem = 0
		for k in range(m):
			if t[k] == '*':
				col[k] += 1
				dem += 1
		row.append(dem)
	rmx = max(row)
	cmx = max(col)
	for j in range(n):
		if row[j] == rmx:
			for k in range(m):
				if col[k] == cmx:
					if inp[j][k] == '*':
						t = n - cmx + (m - rmx)
						kq = min(kq, t)
					else:
						t = n - cmx + (m - rmx) - 1
						kq = min(kq, t)
	print(kq)


from collections import defaultdict
q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	grid = []
	for _ in range(n):
		s = input()
		grid.append(s)
	rows = defaultdict(int)
	cols = defaultdict(int)
	for i in range(n):
		for j in range(m):
			if grid[i][j] == '*':
				rows[i] += 1
				cols[j] += 1
	if not rows:
		ans = m + n - 1
	else:
		maxrows = max(rows.values())
		maxcols = max(cols.values())
		ans = m - maxrows + n - maxcols
		found = False
		for i in rows:
			if rows[i] != maxrows:
				continue
			for j in cols:
				if cols[j] != maxcols:
					continue
				if grid[i][j] == '.':
					ans -= 1
					found = True
					break
			if found:
				break
	print(ans)


q = int(input())
for w in range(q):
	(n, m) = map(int, input().split())
	a = [[i for i in input()] for j in range(n)]
	co = [0] * m
	ro = [0] * n
	for i in range(n):
		for j in range(m):
			if a[i][j] == '.':
				ro[i] += 1
				co[j] += 1
	mi = 10 ** 5
	for i in range(n):
		for j in range(m):
			if a[i][j] == '.':
				k = ro[i] + co[j] - 1
			else:
				k = ro[i] + co[j]
			if k < mi:
				mi = k
	print(mi)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	a = []
	for _ in range(n):
		a.append(list(input()))
	x = float('inf')
	for i in range(n):
		lx = 0
		for j in range(m):
			if a[i][j] == '.':
				lx += 1
		x = min(lx, x)
	k = []
	for i in range(n):
		p = set()
		for j in range(m):
			if a[i][j] == '.':
				p.add((i, j))
		if len(p) == x:
			k.append(p)
	y = float('inf')
	for j in range(m):
		ly = 0
		for i in range(n):
			if a[i][j] == '.':
				ly += 1
		y = min(ly, y)
	l = []
	for j in range(m):
		p = set()
		for i in range(n):
			if a[i][j] == '.':
				p.add((i, j))
		if len(p) == y:
			l.append(p)
	u = float('inf')
	for i in k:
		for j in l:
			u = min(u, len(i.union(j)))
	print(u)


def check(x, y, vert, gor, matrix):
	if matrix[y][x] == 1:
		return gor[y] + vert[x] - 1
	else:
		return gor[y] + vert[x]
q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	vert = [0 for i in range(m)]
	gor = []
	matrix = []
	for s in range(n):
		inp = [int(i == '.') for i in list(input())]
		for u in range(m):
			vert[u] += inp[u]
		gor.append(sum(inp))
		matrix.append(inp)
	minh = 10000000000.0
	for y in range(n):
		for x in range(m):
			u = check(x, y, vert, gor, matrix)
			if u < minh:
				minh = u
	print(minh)


num_queries = int(input())
for _ in range(num_queries):
	(num_rows, num_columns) = map(int, input().split())
	column_blacks = [0] * num_columns
	max_blacks_row = 0
	selected_rows = []
	for num_row in range(num_rows):
		row = input()
		blacks_in_row = 0
		for num_column in range(num_columns):
			if row[num_column] == '*':
				blacks_in_row += 1
				column_blacks[num_column] += 1
		if blacks_in_row > max_blacks_row:
			max_blacks_row = blacks_in_row
			selected_rows = [row]
		elif blacks_in_row == max_blacks_row:
			selected_rows.append(row)
	selected_columns = set()
	max_blacks_col = 0
	for num_column in range(num_columns):
		if column_blacks[num_column] > max_blacks_col:
			max_blacks_col = column_blacks[num_column]
			selected_columns = {num_column}
		elif column_blacks[num_column] == max_blacks_col:
			selected_columns.add(num_column)
	solution = num_rows - max_blacks_col + num_columns - max_blacks_row
	stop = False
	for row in selected_rows:
		for column in selected_columns:
			if row[column] == '.':
				solution -= 1
				stop = True
				break
		if stop:
			break
	print(solution)


for t in range(1, int(input()) + 1):
	(n, m) = map(int, input().split())
	mat = [[1 if c == '*' else 0 for c in input()] for x in range(n)]
	h = [sum(l) for l in mat]
	v = [0] * m
	for i in range(n):
		for j in range(m):
			v[j] += mat[i][j]
	res = float('inf')
	for i in range(n):
		for j in range(m):
			val = n - h[i] + (m - v[j])
			if mat[i][j] == 0:
				val -= 1
			res = min(res, val)
	print(res)


t = int(input())
for i in range(t):
	(m, n) = map(int, input().split())
	d = []
	z = []
	for j in range(m):
		a = input()
		d.append(a)
	maxcntr = 0
	for h in range(m):
		j = d[h]
		cntr = 0
		for k in range(n):
			if j[k] == '*':
				cntr += 1
		if cntr > maxcntr:
			maxcntr = cntr
	for h in range(m):
		j = d[h]
		cntr = 0
		for k in range(n):
			if j[k] == '*':
				cntr += 1
		if cntr == maxcntr:
			z.append(h)
	maxcntc = 0
	x = []
	for h in range(n):
		l = 0
		cntc = 0
		while l < m:
			j = d[l]
			if j[h] == '*':
				cntc += 1
			l += 1
		if cntc > maxcntc:
			maxcntc = cntc
	for h in range(n):
		l = 0
		cntc = 0
		while l < m:
			j = d[l]
			if j[h] == '*':
				cntc += 1
			l += 1
		if cntc == maxcntc:
			x.append(h)
	mina = n - maxcntc + m - maxcntr
	flag = 0
	for j in z:
		minm = n - maxcntc + m - maxcntr
		for k in x:
			if d[j][k] == '.':
				mina -= 1
				flag = 1
				break
		if flag == 1:
			break
	print(mina)


def minh(chkr, n, m):
	l = []
	for i in range(n):
		c = 0
		for j in range(m):
			if chkr[i][j] == '.':
				c += 1
		l.append(c)
	return l

def minv(chkr, n, m):
	l = []
	for j in range(m):
		c = 0
		for i in range(n):
			if chkr[i][j] == '.':
				c += 1
		l.append(c)
	return l
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	chkr = []
	for i in range(n):
		chkr.append(list(input().strip()))
	lh = minh(chkr, n, m)
	lv = minv(chkr, n, m)
	minmin = 10 ** 10
	for i in range(n):
		for j in range(m):
			if chkr[i][j] == '*':
				minmin = min(minmin, lh[i] + lv[j])
			else:
				minmin = min(minmin, lh[i] + lv[j] - 1)
	print(minmin)


ll = lambda : list(map(int, input().split()))
testcases = 1
testcases = int(input())
for testcase in range(testcases):
	[n, m] = ll()
	mat = []
	for i in range(n):
		mat.append(input())
	mt = []
	for i in mat:
		l = []
		for j in i:
			if j == '*':
				l.append(1)
			else:
				l.append(0)
		mt.append(l)
	rowsum = [sum(mt[i]) for i in range(n)]
	colsum = []
	for i in range(m):
		x = 0
		for j in range(n):
			x += mt[j][i]
		colsum.append(x)
	rans = 100000000000000
	for i in range(n):
		for j in range(m):
			ans = n - rowsum[i] + m - colsum[j] - (mt[i][j] == 0)
			rans = min(ans, rans)
	print(rans)


q = int(input())
for i in range(q):
	matrix = []
	(n, m) = map(int, input().split())
	x = [0 for j in range(n)]
	y = [0 for j in range(m)]
	for j in range(n):
		s = str(input())
		matrix.append(s)
		for k in range(m):
			if s[k] == '.':
				x[j] += 1
				y[k] += 1
	ans = n + m
	for j in range(n):
		for k in range(m):
			if matrix[j][k] == '.':
				flag = 1
			else:
				flag = 0
			ans = min(ans, x[j] + y[k] - flag)
	print(ans)


def __starting_point():
	T = int(input())
	for _ in range(T):
		s = input().rstrip().split()
		n = int(s[0])
		m = int(s[1])
		cell = [[0 for j in range(m)] for i in range(n)]
		r = [0 for i in range(n)]
		c = [0 for j in range(m)]
		for i in range(n):
			s = input()
			for j in range(len(s)):
				cell[i][j] = s[j]
				if s[j] == '*':
					r[i] += 1
					c[j] += 1
		nmax = 0
		for i in range(n):
			for j in range(m):
				if r[i] + c[j] + (cell[i][j] == '.') > nmax:
					nmax = r[i] + c[j] + (cell[i][j] == '.')
		print(str(m + n - nmax) + '\n')
__starting_point()


q = int(input())
for w in range(q):
	(n, m) = [int(s) for s in input().split()]
	arr = [[0] * m for i in range(n)]
	for i in range(n):
		s = input()
		for j in range(m):
			if s[j] == '*':
				arr[i][j] = 1
	rec = 0
	sum_i = [0] * n
	for i in range(n):
		for j in range(m):
			sum_i[i] += arr[i][j]
	sum_j = [0] * m
	for j in range(m):
		for i in range(n):
			sum_j[j] += arr[i][j]
	for i in range(n):
		for j in range(m):
			rec = max(rec, sum_i[i] + sum_j[j] - arr[i][j])
	print(n + m - 1 - rec)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	mat = []
	row = []
	col = []
	for i in range(n):
		l = input()
		temp = l.count('.')
		row.append(temp)
		mat.append(l)
	for i in range(m):
		l = [sub[i] for sub in mat]
		temp = l.count('.')
		col.append(temp)
	mi = 9999999999
	for i in range(n):
		for j in range(m):
			ans = row[i] + col[j]
			if mat[i][j] == '.':
				ans -= 1
			if ans < mi:
				mi = ans
	print(mi)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	a = []
	for j in range(n):
		a.append(list(input()))
	q = []
	w = []
	for j in range(n):
		c = 0
		for k in range(m):
			if a[j][k] == '*':
				c = c + 1
		q.append(c)
	for j in range(m):
		c = 0
		for k in range(n):
			if a[k][j] == '*':
				c = c + 1
		w.append(c)
	qw = 0
	qq = max(q)
	ww = max(w)
	for j in range(len(q)):
		if q[j] == qq:
			for k in range(len(w)):
				if w[k] == ww:
					if a[j][k] == '.':
						qw = 1
						break
			if qw == 1:
				break
	print(n - max(w) + m - max(q) - qw)


def f(i, j, curmas):
	if curmas[i][j] == '.':
		return 0
	return 1
n = int(input())
mas = [None] * n
maspar = [None] * n
for x in range(n):
	parametrs = list(map(int, input().split()))
	maspar[x] = parametrs
	m = [list((z for z in input())) for i in range(parametrs[0])]
	mas[x] = m
ans = 0
for x in range(n):
	curmas = mas[x]
	p = curmas[:]
	lines = maspar[x][0]
	cols = maspar[x][1]
	alans = 0
	maslines = [None] * lines
	for i in range(lines):
		maslines[i] = curmas[i].count('*')
	mascols = [None] * cols
	for i in range(cols):
		mascols[i] = [q[i] for q in curmas].count('*')
	for i in range(lines):
		for j in range(cols):
			if maslines[i] + mascols[j] - f(i, j, curmas) > alans:
				alans = maslines[i] + mascols[j] - f(i, j, curmas)
	print(lines + cols - alans - 1)


import sys
for q in range(int(sys.stdin.readline())):
	(n, m) = [int(i) for i in sys.stdin.readline().split()]
	data = []
	for i in range(n):
		data.append(sys.stdin.readline())
	row = [0] * n
	col = [0] * m
	for i in range(n):
		for j in range(m):
			if data[i][j] == '*':
				row[i] += 1
				col[j] += 1
	mxrow = max(row)
	mxcol = max(col)
	ans = n + m - mxrow - mxcol
	mrs = set()
	mcs = set()
	for i in range(n):
		if row[i] == mxrow:
			mrs.add(i)
	for i in range(m):
		if col[i] == mxcol:
			mcs.add(i)
	done = False
	for i in range(n):
		for j in range(m):
			if data[i][j] == '.' and i in mrs and (j in mcs):
				ans -= 1
				done = True
				break
		if done:
			break
	sys.stdout.write(str(ans) + '\n')


t = int(input())
for z in range(t):
	(n, m) = map(int, input().split())
	arr = [0 for i in range(n)]
	for i in range(n):
		arr[i] = list(input())
	gor = [0 for i in range(n)]
	ver = [0 for i in range(m)]
	for i in range(n):
		for j in range(m):
			if arr[i][j] != '*':
				gor[i] += 1
				ver[j] += 1
	ans = 1000000000000
	for i in range(n):
		for j in range(m):
			ans = min(ans, gor[i] + ver[j] - (1 if arr[i][j] == '.' else 0))
	print(ans)


import sys
input = sys.stdin.readline
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left
import math
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(list(input()[:-1]))
	r = dc(int)
	c = dc(int)
	for i in range(n):
		for j in range(m):
			if l[i][j] == '.':
				r[i] += 1
				c[j] += 1
	k = sys.maxsize
	for i in range(n):
		for j in range(m):
			if l[i][j] == '.':
				k = min(k, r[i] + c[j] - 1)
			else:
				k = min(k, r[i] + c[j])
	print(k)


q = int(input())
ans_arr = []
for x in range(q):
	[n, m] = [int(i) for i in input().split()]
	rowhash = []
	for p in range(n):
		rowhash.append(0)
	arr = []
	for k in range(n):
		s = input()
		arr.append(s)
	row = m
	for i in range(n):
		ctr = 0
		for j in range(m):
			if arr[i][j] == '.':
				ctr += 1
		row = min(ctr, row)
	for i in range(n):
		ch = 0
		for j in range(m):
			if arr[i][j] == '.':
				ch += 1
		if ch == row:
			rowhash[i] = 1
	col = n
	for i in range(m):
		ct = 0
		flag = 0
		for j in range(n):
			if arr[j][i] == '.':
				ct += 1
			if arr[j][i] == '.' and rowhash[j] == 1:
				flag = 1
		if flag == 1:
			ct = max(ct - 1, 0)
		col = min(ct, col)
	ans_arr.append(row + col)
for g in range(q):
	print(ans_arr[g])


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		s = input()
		l.append(s)
	rows = [0] * n
	columns = [0] * m
	for i in range(n):
		for j in range(m):
			if l[i][j] == '.':
				rows[i] += 1
				columns[j] += 1
	ans = n + m
	for i in range(n):
		for j in range(m):
			ans = min(ans, rows[i] + columns[j] - (l[i][j] == '.'))
	print(ans)


for _ in [0] * int(input()):
	a = [input() for _ in [0] * int(input().split()[0])]
	(b, c) = ([x.count('.') for x in y] for y in (a, zip(*a)))
	print(min((s + t - (x > '*') for (r, s) in zip(a, b) for (x, t) in zip(r, c))))


q = int(input())
(w, h) = (50000, 50000)
for T in range(q):
	(n, m) = list(map(int, input().split()))
	row = [0] * n
	col = [0] * m
	Matrix = ''
	for i in range(n):
		s = input()
		Matrix += s
		for j in range(m):
			if s[j] == '*':
				row[i] += 1
				col[j] += 1
	minima = float('inf')
	p1 = -1
	p2 = -1
	for i in range(n):
		for j in range(m):
			res = n + m - (row[i] + col[j])
			idx = i * m + j
			if Matrix[idx] == '.':
				res -= 1
			minima = min(minima, res)
	print(minima)


q = int(input())
for i in range(q):
	(n, m) = list(map(int, input().split()))
	field = [input() for j in range(n)]
	raw = [0] * n
	col = [0] * m
	num = 0
	for j in range(n):
		for z in range(m):
			if field[j][z] == '*':
				raw[j] += 1
				col[z] += 1
	for z in range(m):
		for j in range(n):
			temp = raw[j] + col[z] - int(field[j][z] == '*')
			if num < temp:
				num = temp
	print(n + m - num - 1)


q = int(input())
for i in range(q):
	(w, e) = map(int, input().split())
	r = [0] * w
	for j in range(w):
		r[j] = input()
	t = [0] * e
	mx = [-1]
	m = -1
	for k in range(w):
		sum = 0
		for j in range(e):
			if r[k][j] == '*':
				t[j] += 1
				sum += 1
		if sum > m:
			mx = [k]
			m = sum
		elif sum == m:
			mx.append(k)
	mq = -1
	mxq = [-1]
	for j in range(e):
		if t[j] > mq:
			mq = t[j]
			mxq = [j]
		elif t[j] == mq:
			mxq.append(j)
	true = False
	for j in mx:
		for k in mxq:
			if r[j][k] == '.':
				true = True
	if true:
		print(w - m + e - mq - 1)
	else:
		print(w - m + e - mq)


import sys
input = lambda : sys.stdin.readline().strip()
print = lambda x: sys.stdout.write(f'{x}\n')
for t in range(int(input())):
	(r, c) = map(int, input().split())
	arr = [input() for i in range(r)]
	rarr = [0] * r
	carr = [0] * c
	for i in range(r):
		for j in range(c):
			if arr[i][j] == '.':
				rarr[i] += 1
				carr[j] += 1
	ans = float('inf')
	for i in range(r):
		for j in range(c):
			s = rarr[i] + carr[j]
			if arr[i][j] == '.':
				ans = min(ans, s - 1)
			else:
				ans = min(ans, s)
	print(ans)


n = int(input())
for i in range(n):
	(x, y) = map(int, input().split())
	stolb = [0] * y
	stroki = [0] * x
	al = []
	for j in range(x):
		st = input()
		al.append(st)
		for j2 in range(y):
			if st[j2] == '.':
				stroki[j] += 1
				stolb[j2] += 1
	mi = 1000000000000000
	for j in range(x):
		for j2 in range(y):
			if al[j][j2] == '.':
				if stroki[j] + stolb[j2] - 1 < mi:
					mi = stroki[j] + stolb[j2] - 1
			elif stroki[j] + stolb[j2] < mi:
				mi = stroki[j] + stolb[j2]
	print(mi)


from sys import stdin, stdout
q = int(stdin.readline())
for i in range(q):
	(n, m) = [int(c) for c in stdin.readline().split()]
	rows = [0] * n
	cols = [0] * m
	data = []
	for j in range(n):
		row = stdin.readline()
		data.append(row)
		for k in range(m):
			if row[k] == '.':
				rows[j] += 1
				cols[k] += 1
	min_sum = 1000000
	for j in range(n):
		for k in range(m):
			curr_sum = rows[j] + cols[k]
			if curr_sum <= min_sum:
				if data[j][k] == '.':
					min_sum = curr_sum - 1
				else:
					min_sum = curr_sum
	stdout.write(str(min_sum) + '\n')


T = int(input())

def main():
	(X, Y) = map(int, input().split())
	values = [[0] * Y for _ in range(X)]
	for x in range(X):
		s = input()
		for y in range(Y):
			values[x][y] = 0 if s[y] == '*' else 1
	sumX = [sum(values[x]) for x in range(X)]
	sumY = [sum((values[x][y] for x in range(X))) for y in range(Y)]
	print(min((min((sumX[x] + sumY[y] - values[x][y] for y in range(Y))) for x in range(X))))
for _ in range(T):
	main()


import io, sys, atexit, os
import math as ma
from sys import exit
from decimal import Decimal as dec
from itertools import permutations
from itertools import combinations

def li():
	return list(map(int, input().split()))

def num():
	return map(int, input().split())

def nu():
	return int(input())

def find_gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x

def lcm(x, y):
	gg = find_gcd(x, y)
	return x * y // gg
mm = 1000000007
yp = 0

def solve():
	t = nu()
	for tt in range(t):
		(n, m) = num()
		a = [0] * n
		x = [0] * n
		y = [0] * m
		for i in range(n):
			p = input()
			a[i] = [0] * m
			for j in range(m):
				if p[j] == '*':
					a[i][j] = 1
			x[i] = sum(a[i])
		for i in range(m):
			cc = 0
			for j in range(n):
				cc += a[j][i]
			y[i] = cc
		mn = 9999999999
		for i in range(n):
			for j in range(m):
				pp = 0
				pp = n - x[i] + (m - y[j])
				if a[i][j] == 0:
					pp -= 1
				mn = min(mn, pp)
		print(mn)
solve()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	c = [0 for i in range(m)]
	d = []
	l = []
	for i in range(n):
		a = input()
		l.append(a)
		d.append(a.count('*'))
		for j in range(m):
			if a[j] == '*':
				c[j] += 1
	c1 = max(c)
	d1 = max(d)
	c2 = []
	d2 = []
	for i in range(m):
		if c[i] == c1:
			c2.append(i)
	for i in range(n):
		if d[i] == d1:
			d2.append(i)
	if c1 == m and d1 == n:
		print(0)
	else:
		ans = 0
		for i in d2:
			for j in c2:
				if l[i][j] == '.':
					ans = 1
					break
			if ans == 1:
				break
		print(m + n - c1 - d1 - ans)


T = int(input())
for _ in range(0, T):
	(n, m) = map(int, input().split())
	arr = []
	for i in range(0, n):
		s = input()
		arr.append(s)
	ans = n + m - 1
	L1 = []
	L2 = []
	for i in range(n):
		c = 0
		for j in range(m):
			if arr[i][j] == '.':
				c += 1
		L1.append((i, c))
	for i in range(m):
		c = 0
		for j in range(n):
			if arr[j][i] == '.':
				c += 1
		L2.append((i, c))
	for i in range(0, len(L1)):
		for j in range(0, len(L2)):
			c = L1[i][1] + L2[j][1]
			if arr[L1[i][0]][L2[j][0]] == '.':
				c -= 1
			ans = min(ans, c)
	print(ans)


def main():
	q = int(input())
	for _ in range(q):
		(n, m) = map(int, input().split())
		tab = []
		for x in range(n):
			tab.append(input())
		v = [0] * n
		hor = [0] * m
		for x in range(n):
			for y in range(m):
				if tab[x][y] == '*':
					v[x] += 1
					hor[y] += 1
		mi = 1000 * 1000
		for x in range(n):
			for y in range(m):
				o = 0
				if tab[x][y] == '.':
					o = 1
				mi = min(mi, n - v[x] + (m - hor[y]) - o)
		print(mi)
main()


import sys
input = sys.stdin.readline
Q = int(input())
for testcases in range(Q):
	(n, m) = map(int, input().split())
	MAP = [list(input().strip()) for i in range(n)]
	R = [MAP[i].count('*') for i in range(n)]
	C = []
	for j in range(m):
		M = [MAP[i][j] for i in range(n)]
		C.append(M.count('*'))
	ANS = float('inf')
	for i in range(n):
		for j in range(m):
			if MAP[i][j] == '*':
				ANS = min(ANS, n + m - R[i] - C[j])
			else:
				ANS = min(ANS, n + m - R[i] - C[j] - 1)
	print(ANS)


q = int(input())

def solve(a, n, m):
	row = [0 for i in range(0, n)]
	column = [0 for i in range(0, m)]
	for i in range(0, n):
		count = 0
		for j in range(0, m):
			if a[i][j] == '.':
				count += 1
		row[i] = count
	for i in range(0, m):
		count = 0
		for j in range(0, n):
			if a[j][i] == '.':
				count += 1
		column[i] = count
	ans = 1000000009
	for i in range(0, n):
		for j in range(0, m):
			temp = row[i] + column[j]
			if a[i][j] == '.':
				temp -= 1
			ans = min(ans, temp)
	print(ans)
while q > 0:
	q -= 1
	(n, m) = map(int, input().split())
	a = []
	for i in range(0, n):
		a.append(input())
	solve(a, n, m)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	board = [input() for _ in range(n)]
	cn = 10 ** 10
	candn = []
	cm = 10 ** 10
	candm = []
	for i in range(n):
		tmp = 0
		for j in range(m):
			if board[i][j] == '.':
				tmp += 1
		if tmp < cn:
			cn = tmp
			candn = [i]
		elif tmp == cn:
			candn.append(i)
	for i in range(m):
		tmp = 0
		for j in range(n):
			if board[j][i] == '.':
				tmp += 1
		if tmp < cm:
			cm = tmp
			candm = [i]
		elif tmp == cm:
			candm.append(i)
	if cn == 0 or cm == 0:
		print(cn + cm)
	else:
		flag = False
		for i in candn:
			for j in range(m):
				if board[i][j] == '.':
					if j in candm:
						flag = True
		if flag == False:
			print(cn + cm)
		else:
			print(cn + cm - 1)


q = int(input())
for query in range(q):
	(n, m) = map(int, input().split())
	matrix = [input() for i in range(n)]
	row = [0] * n
	col = [0] * m
	for i in range(n):
		suma = 0
		for j in range(m):
			if matrix[i][j] == '*':
				suma += 1
		row[i] = suma
	for j in range(m):
		suma = 0
		for i in range(n):
			if matrix[i][j] == '*':
				suma += 1
		col[j] = suma
	wynik = 100000000000
	for i in range(n):
		for j in range(m):
			pom = m + n - 1 - (row[i] + col[j] - (1 if matrix[i][j] == '*' else 0))
			wynik = min(wynik, pom)
	print(wynik)


for i in range(int(input())):
	(n, m) = list(map(int, input().split()))
	xMin = 999999999999
	yMin = 999999999999
	arr = []
	for i in range(n):
		arr.append(list(input()))
	ans = n + m - 1
	r = [0] * m
	c = [0] * n
	for i in range(n):
		for g in range(m):
			if arr[i][g] == '.':
				c[i] += 1
				r[g] += 1
	for i in range(n):
		for g in range(m):
			ans = min(ans, c[i] + r[g] - (arr[i][g] == '.'))
	print(ans)


req_cnt = int(input())
for i in range(req_cnt):
	(n, m) = map(int, input().split())
	matrix = [None] * n
	for i in range(n):
		matrix[i] = input()
	countsLN = [0] * n
	countsCL = [0] * m
	for i in range(n):
		for j in range(m):
			if matrix[i][j] == '*':
				countsLN[i] += 1
				countsCL[j] += 1
	bst_res = 999999999
	for i in range(n):
		for j in range(m):
			lackLN = n - countsLN[i]
			lackCL = m - countsCL[j]
			cost = lackLN + lackCL
			if matrix[i][j] == '.':
				cost -= 1
			if cost < bst_res:
				bst_res = cost
	print(bst_res)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = [input() for i in range(n)]
	r = [0] * n
	c = [0] * m
	for i in range(n):
		for j in range(m):
			if a[i][j] == '*':
				r[i] += 1
				c[j] += 1
	mr = max(r)
	mc = max(c)
	ans = n + m - mr - mc
	z = n + m - mr - mc
	for i in range(n):
		for j in range(m):
			if r[i] == mr and c[j] == mc:
				ans = min(ans, z - int(a[i][j] == '.'))
	print(ans)


t = int(input())
for i in range(0, t):
	pic = []
	(n, m) = map(int, input().split())
	for j in range(0, n):
		pic.append(input())
	minRow = [0]
	minSqaresR = 5000000
	for j in range(0, n):
		squares = pic[j].count('.')
		if squares < minSqaresR:
			minSqaresR = squares
			minRow = [j]
		elif squares == minSqaresR:
			minRow.append(j)
	minCol = [0]
	minSqaresC = 5000000
	transp = list(zip(*pic))
	for j in range(0, m):
		squares = transp[j].count('.')
		if squares < minSqaresC:
			minSqaresC = squares
			minCol = [j]
		elif squares == minSqaresC:
			minCol.append(j)
	modifier = 0
	for j in range(0, len(minRow)):
		if modifier == -1:
			break
		for k in range(0, len(minCol)):
			if pic[minRow[j]][minCol[k]] == '.':
				modifier = -1
				break
	print(minSqaresR + minSqaresC + modifier)


tc = int(input())
while tc:
	tc -= 1
	(n, m) = [int(x) for x in input().split()]
	R = [0] * n
	C = [0] * m
	ar = [input() for i in range(n)]
	for (i, x) in enumerate(ar):
		for (j, y) in enumerate(x):
			if y == '*':
				R[i] += 1
				C[j] += 1
	ans = n * m
	for (i, x) in enumerate(ar):
		for (j, y) in enumerate(x):
			tmp = m - R[i] + n - C[j] - (y != '*')
			if tmp < ans:
				ans = tmp
	print(ans)


def findOverlap(maxColIdx, maxRowMissingIdx):
	for i in maxColIdx:
		for missing in maxRowMissingIdx:
			if i in missing:
				return True
	return False
for _ in range(int(input())):
	(row, column) = map(int, input().split())
	col_count_list = [0] * column
	max_row_count = 0
	max_row_missing = []
	for _ in range(row):
		line = input()
		cur_row_count = 0
		cur_row_missing = []
		for i in range(column):
			if line[i] == '*':
				col_count_list[i] += 1
				cur_row_count += 1
			else:
				cur_row_missing.append(i)
		if cur_row_count > max_row_count:
			max_row_count = cur_row_count
			max_row_missing = [cur_row_missing]
		elif cur_row_count == max_row_count:
			max_row_missing.append(cur_row_missing)
	max_col_count = max(col_count_list)
	if max_col_count == column and max_row_count == row:
		print(0)
	else:
		result = column - max_col_count + (row - max_row_count)
		indices = [i for (i, x) in enumerate(col_count_list) if x == max_col_count]
		if findOverlap(indices, max_row_missing):
			print(result - 1)
		else:
			print(result)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	row = [0] * n
	col = [0] * m
	arr = [''] * n
	for i in range(n):
		s = input()
		arr[i] = s
		for j in range(m):
			if s[j] == '*':
				row[i] += 1
				col[j] += 1
	ans = n * m
	for i in range(n):
		for j in range(m):
			ans = min(ans, m - row[i] + n - col[j] - (arr[i][j] == '.'))
	print(ans)


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	T = []
	(R, C) = ([0] * n, [0] * m)
	for j in range(n):
		row = input()
		R[j] = row.count('*')
		T.append(row)
		for k in range(m):
			if row[k] == '*':
				C[k] += 1
	ans = n + m - 1
	for j in range(n):
		for k in range(m):
			if T[j][k] == '*':
				ans = min(ans, n + m - 1 - R[j] - C[k] + 1)
			else:
				ans = min(ans, n + m - 1 - R[j] - C[k])
	print(ans)


from sys import stdin
c = int(stdin.readline().strip())
for i in range(c):
	(n, m) = map(int, stdin.readline().strip().split())
	s = [stdin.readline().strip() for j in range(n)]
	ms = []
	ns = []
	for j in range(n):
		ns.append(s[j].count('.'))
	for j in range(m):
		ms.append(0)
		for k in range(n):
			if s[k][j] == '.':
				ms[-1] += 1
	ans = 10 ** 15
	for j in range(n):
		for k in range(m):
			x = ns[j] + ms[k]
			if s[j][k] == '.':
				x -= 1
			ans = min(ans, x)
	print(ans)


import math
import sys
import collections

def cdiv(n, k):
	return n // k + (n % k != 0)

def ii():
	return int(input())

def mi():
	return map(int, input().split())

def li():
	return list(map(int, input().split()))

def l(d):
	res = []
	for i in d:
		res.append(i.count('.'))
	return res

def r(d, n, m):
	res = []
	for j in range(m):
		t = 0
		for i in range(n):
			if d[i][j] == '.':
				t += 1
		res.append(t)
	return res
t = ii()
for i in range(t):
	(n, m) = mi()
	d = []
	for i in range(n):
		d.append(input())
	cl = l(d)
	cr = r(d, n, m)
	res = n * m
	for i in range(n):
		for j in range(m):
			res = min(res, cl[i] + cr[j] - (d[i][j] == '.'))
	print(res)


q = int(input())
for query in range(q):
	(n, m) = map(int, input().split(' '))
	(row_max, col_max, min_time) = ([0] * n, [0] * m, n * m)
	picture = []
	for i in range(n):
		row_data = input()
		for j in range(m):
			if row_data[j] == '.':
				row_max[i] += 1
				col_max[j] += 1
		picture.append(row_data)
	for i in range(n):
		for j in range(m):
			curr_min_time = row_max[i] + col_max[j]
			if curr_min_time <= min_time:
				if picture[i][j] == '.':
					min_time = curr_min_time - 1
				else:
					min_time = curr_min_time
	print(min_time)


n = int(input())
for i in range(0, n):
	l = []
	q = []
	w = []
	S = []
	D = []
	o = input().rstrip().split(' ')
	for j in range(0, int(o[0])):
		p = input().rstrip()
		p = list(p)
		l.append(p)
		q.append(p.count('*'))
	L = list(l)
	l = [list(x) for x in zip(*l)]
	for j in range(0, len(l)):
		w.append(l[j].count('*'))
	C = list(w)
	F = []
	for j in range(0, len(L)):
		BB = 0
		N = list(C)
		for k in range(0, len(L[j])):
			if L[j][k] != '*':
				BB += 1
				N[k] += 1
		H = max(N)
		F.append(BB + (int(o[0]) - H))
	print(min(F))


from collections import Counter
q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	a = []
	max_row = 0
	max_col = 0
	cols = [0] * m
	rows = [0] * n
	for i in range(n):
		s = input()
		a.append(s)
		rows[i] = Counter(s)['*']
	for i in range(n):
		for j in range(m):
			if a[i][j] == '*':
				cols[j] += 1
	result = n * m
	for i in range(n):
		for j in range(m):
			x = max(0, m - rows[i])
			y = max(0, n - cols[j])
			flag = a[i][j] == '.'
			result = min(result, max(0, x + y - flag))
	print(result)


for _ in range(int(input())):
	(row, column) = map(int, input().split())
	if row == 1:
		print(input().count('.'))
	else:
		(matrix, blacks, capt) = ([0] * column, [], [])
		for x in range(row):
			r = input()
			blacks.append(r.count('.'))
			capt.append(r)
			for k in range(column):
				if r[k] == '.':
					matrix[k] += 1
		(trap, res) = ([], [])
		for c in range(row):
			trap.extend(matrix)
			for x in range(column):
				if capt[c][x] == '.':
					trap[x] -= 1
			res.append(blacks[c] + min(trap))
			trap = []
		print(min(res))


def MI():
	return map(int, input().split())

def I():
	return int(input())

def LI():
	return [int(i) for i in input().split()]
t = I()
for i in range(t):
	(n, m) = MI()
	(h, v) = ([0] * n, [0] * m)
	d = []
	for i in range(n):
		s = [1 if i == '*' else 0 for i in input()]
		h[i] = sum(s)
		d += s
	c = n + m
	for i in range(m):
		for j in range(n):
			v[i] += d[m * j + i]
	for i in range(n):
		for j in range(m):
			c = min(m - h[i] + n - v[j] - (1 - d[m * i + j]), c)
	print(c)


q = int(input())
for i in range(q):
	ints = [int(x) for x in input().split()]
	arr = []
	smallRows = []
	periodsCorresponding = []
	minNumInRow = ints[1] + 1
	numPeriodInCol = [0 for m in range(ints[1])]
	for j in range(ints[0]):
		n = input()
		arr.append(n)
		minNum = 0
		periods = []
		for k in range(len(n)):
			if n[k] == '.':
				numPeriodInCol[k] += 1
				minNum += 1
				periods.append(k)
		if minNum < minNumInRow:
			smallRows = [j]
			periodsCorresponding = [periods]
			minNumInRow = minNum
		elif minNum == minNumInRow:
			smallRows.append(j)
			periodsCorresponding.append(periods)
	minPeriodColumn = min(numPeriodInCol)
	flag = False
	for i in range(len(periodsCorresponding)):
		for j in range(len(periodsCorresponding[i])):
			if numPeriodInCol[periodsCorresponding[i][j]] == minPeriodColumn:
				flag = True
				break
		if flag == True:
			break
	if flag == True:
		print(minNumInRow + minPeriodColumn - 1)
	else:
		print(minNumInRow + minPeriodColumn)


for _ in [0] * int(input()):
	(n, m) = map(int, input().split())
	a = [input() for _ in [0] * n]
	(b, c) = ([x.count('.') for x in y] for y in (a, zip(*a)))
	print(min((b[i] + c[j] - (a[i][j] > '*') for i in range(n) for j in range(m))))


import sys
Q = int(input())
for _ in range(Q):
	(N, M) = map(int, sys.stdin.readline().split())
	G = [[1 if s == '*' else 0 for s in sys.stdin.readline().strip()] for _ in range(N)]
	ans = 10 ** 9 + 7
	G1 = [sum(g) for g in G]
	G = list(map(list, zip(*G)))
	G2 = [sum(g) for g in G]
	G = list(map(list, zip(*G)))
	K = N + M - 1
	for i in range(N):
		for j in range(M):
			if G[i][j]:
				ans = min(ans, K - (G1[i] + G2[j] - 1))
			else:
				ans = min(ans, K - (G1[i] + G2[j]))
	sys.stdout.write('{}\n'.format(ans))


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	d = [list(input()) for _ in range(n)]
	count_x = list(map(lambda x: x.count('*'), d))
	count_y = list(map(lambda x: x.count('*'), zip(*d)))
	rls = n + m - 1
	for i in range(n):
		for j in range(m):
			a = count_x[i]
			b = count_y[j]
			if d[i][j] == '*':
				rls = min(rls, n + m - a - b)
			else:
				rls = min(rls, n + m - a - b - 1)
	print(rls)


from sys import stdin
input = stdin.readline
for i in range(int(input())):
	(n, m) = map(int, input().split())
	g = [0] * m
	f = [0] * n
	field = ''
	for i in range(n):
		s = input().strip()
		field += s
		for j in range(m):
			if s[j] == '.':
				g[j] += 1
				f[i] += 1
	ans = n + m
	for i in range(n):
		for j in range(m):
			x = f[i] + g[j]
			idx = i * m + j
			if field[idx] == '.':
				x -= 1
			ans = min(ans, x)
	print(ans)


t = int(input())
for you in range(t):
	l = input().split()
	n = int(l[0])
	m = int(l[1])
	l = []
	for i in range(n):
		s = input()
		l.append(s)
	maxa = 0
	lr = []
	for i in range(n):
		count = 0
		for j in range(m):
			if l[i][j] == '*':
				count += 1
		lr.append(count)
	maxa = 0
	lc = []
	for i in range(m):
		count = 0
		for j in range(n):
			if l[j][i] == '*':
				count += 1
		lc.append(count)
	ans = 10 ** 18
	for i in range(n):
		for j in range(m):
			if l[i][j] == '*':
				ans = min(ans, n + m - lr[i] - lc[j])
			else:
				ans = min(ans, n + m - lr[i] - lc[j] - 1)
	print(ans)


t = int(input())
for _ in range(t):
	r = []
	c = []
	mat = []
	(n, m) = map(int, input().split())
	for i in range(n):
		l = input()
		mat.append(l)
		temp = l.count('.')
		r.append(temp)
	for i in range(m):
		l = [sub[i] for sub in mat]
		temp = l.count('.')
		c.append(temp)
	mi = 9999999999
	for i in range(n):
		for j in range(m):
			ans = r[i] + c[j]
			if mat[i][j] == '.':
				ans -= 1
			if ans < mi:
				mi = ans
	print(mi)


t = int(input())
while t != 0:
	t -= 1
	a = input()
	(n, m) = a.split()
	n = int(n)
	m = int(m)
	s = [input() for _ in range(n)]
	p = [0] * n
	q = [0] * m
	for i in range(n):
		for j in range(m):
			if s[i][j] == '*':
				p[i] += 1
				q[j] += 1
	maxi = 0
	for w in range(n):
		for u in range(m):
			if s[w][u] == '*':
				if maxi < p[w] + q[u] - 1:
					maxi = p[w] + q[u] - 1
			elif maxi < p[w] + q[u]:
				maxi = p[w] + q[u]
	print(m + n - maxi - 1)


def kr(a, n, m):
	a_n = []
	a_m = []
	for i in range(m):
		a_m.append(0)
		for j in range(n):
			if a[j][i] == '*':
				a_m[i] += 1
	for i in range(n):
		a_n.append(0)
		for j in range(m):
			if a[i][j] == '*':
				a_n[i] += 1
	mn = 0
	mm = 0
	kn = 0
	km = 0
	for i in range(n):
		if a_n[i] > mn:
			kn = i
			mn = a_n[i]
	for i in range(m):
		if a_m[i] > mm:
			km = i
			mm = a_m[i]
	for i in range(n):
		for j in range(m):
			if a[i][j] == '.' and a_n[i] == mn and (a_m[j] == mm):
				kn = i
				km = j
	return m + n - mn - mm - int(a[kn][km] == '.')
t = int(input())
while t:
	t -= 1
	(n, m) = map(int, input().split())
	a = [0] * n
	for i in range(n):
		k = input()
		a[i] = list(k)
	print(kr(a, n, m))


test = int(input())
for g in range(test):
	(n, k) = map(int, input().split())
	s = []
	ans = n + k
	for i in range(n):
		s.append(list(input()))
	col = [0] * k
	row = [0] * n
	for i in range(n):
		for j in range(k):
			row[i] += s[i][j] == '.'
			col[j] += s[i][j] == '.'
	for i in range(n):
		for j in range(k):
			ans = min(ans, row[i] + col[j] - (s[i][j] == '.'))
	print(ans)


import math as mt
import sys, string, bisect
input = sys.stdin.readline
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())
t = I()
for _ in range(t):
	(n, m) = M()
	l = []
	p = 0
	w = []
	for i in range(n):
		x = list(input().strip())
		w.append(x.count('*'))
		l.append(x)
	r = 0
	y = 10 ** 9
	for j in range(m):
		d = 0
		for i in range(n):
			if l[i][j] == '*':
				d += 1
		for i in range(n):
			if l[i][j] == '*':
				h = m + n - 1 - d - w[i] + 1
				y = min(y, h)
			else:
				b = m + n - 1 - d - w[i]
				y = min(y, b)
	print(y)


q = int(input())
while q > 0:
	(n, m) = map(int, input().split())
	s = []
	for i in range(n):
		s.append(input())
	r = [0] * n
	c = [0] * m
	for i in range(n):
		for j in range(m):
			if s[i][j] == '.':
				r[i] += 1
				c[j] += 1
	ans = n + m - 1
	for i in range(n):
		for j in range(m):
			ans = min(ans, r[i] + c[j] - (s[i][j] == '.'))
	print(ans)
	q -= 1


from sys import stdin
stdin = iter(stdin)
q = int(next(stdin))

def solve():
	(n, m) = map(int, next(stdin).split())
	grid = [next(stdin) for _ in range(n)]
	row_count = [r.count('*') for r in grid]
	col_count = [c.count('*') for c in map(list, zip(*grid))]
	best = n + m
	for i in range(n):
		for j in range(m):
			needed = n + m - row_count[i] - col_count[j] - (0 if grid[i][j] == '*' else 1)
			if needed < best:
				best = needed
	print(best)
for _ in range(q):
	solve()


import collections
for t in range(int(input())):
	(n, m) = map(int, input().split())
	grid = [input() for i in range(n)]
	rows = []
	cols = [0] * m
	for row in grid:
		rows.append(0)
		for i in range(m):
			if row[i] == '.':
				rows[-1] += 1
				cols[i] += 1
	ans = m + n - 1
	for i in range(n):
		for j in range(m):
			ans = min(ans, rows[i] + cols[j] - (grid[i][j] == '.'))
	print(ans)


def process():
	a = []
	s = input()
	b = s.split(' ')
	n = int(b[0])
	m = int(b[1])
	c = []
	for i in range(0, n):
		s = input()
		c = []
		for x in s:
			if x == '*':
				c.append(1)
			else:
				c.append(0)
		a.append(c)
	p = []
	for i in range(0, n):
		sum = 0
		for j in range(0, m):
			sum = sum + a[i][j]
		p.append(sum)
	q = []
	for j in range(0, m):
		sum = 0
		for i in range(0, n):
			sum = sum + a[i][j]
		q.append(sum)
	maxi = 0
	for i in range(0, n):
		for j in range(0, m):
			if p[i] + q[j] - a[i][j] > maxi:
				maxi = p[i] + q[j] - a[i][j]
	print(m + n - 1 - maxi)
q = int(input())
for i in range(0, q):
	process()


t = int(input())
for _ in range(t):
	(m, n) = map(int, input().split(' '))
	b = []
	for _ in range(m):
		b.append(list(input()))
	y = [0] * m
	x = [0] * n
	for i in range(m):
		k = 0
		for j in range(n):
			if b[i][j] == '.':
				k += 1
				x[j] += 1
		y[i] = k
	e = min(y)
	f = []
	for i in range(m):
		if y[i] == e:
			f.append(i)
	g = min(x)
	h = []
	for j in range(n):
		if x[j] == g:
			h.append(j)
	flag = 0
	for i in f:
		for j in h:
			if b[i][j] == '.':
				flag = 1
				break
	if flag == 1:
		print(e + g - 1)
	else:
		print(e + g)


q = int(input())
(ns, xs) = ([], [])
for i in range(q):
	(n, m) = map(int, input().split())
	base = []
	for i in range(n):
		base.append(input())
	ato = [[0 for i in range(m)] for i in range(n)]
	for i in range(n):
		yk_c = 0
		for k in range(m):
			if base[i][k] == '.':
				yk_c += 1
		for k in range(m):
			ato[i][k] += yk_c
	for k in range(m):
		ta_c = 0
		for i in range(n):
			if base[i][k] == '.':
				ta_c += 1
		for i in range(n):
			if base[i][k] == '.':
				ato[i][k] += ta_c - 1
			else:
				ato[i][k] += ta_c
	ans = n * m
	for i in range(n):
		for k in range(m):
			if ato[i][k] < ans:
				ans = ato[i][k]
	print(ans)


n = int(input())
arr = []
arr_razm = []
for b in range(n):
	arr_0 = []
	arr_new = [int(i) for i in filter(None, input().split(' '))]
	for i in range(arr_new[0]):
		arr_0.append(input())
	arr_razm.append(arr_new)
	arr.append(arr_0)
for a in range(n):
	arr_stolb = [0]
	arr_str = [0]
	max_str = 0
	max_stolb = 0
	for i in range(arr_razm[a][0]):
		k_str = 0
		for j in arr[a][i]:
			if j == '*':
				k_str += 1
		if k_str == max_str:
			arr_str.append(i)
		elif k_str > max_str:
			arr_str = []
			arr_str.append(i)
			max_str = k_str
	for i in range(arr_razm[a][1]):
		k_stolb = 0
		for j in range(arr_razm[a][0]):
			if arr[a][j][i] == '*':
				k_stolb += 1
		if k_stolb == max_stolb:
			arr_stolb.append(i)
		elif k_stolb > max_stolb:
			arr_stolb = []
			arr_stolb.append(i)
			max_stolb = k_stolb
	plus = 0
	for i in arr_str:
		for j in arr_stolb:
			if arr[a][i][j] == '.':
				plus = 1
	print(arr_razm[a][1] - max_str + arr_razm[a][0] - max_stolb - plus)


ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
si = lambda : input()
for _ in range(ii()):
	(n, m) = mi()
	p = [list(si()) for i in range(n)]
	r = [0] * n
	c = [0] * m
	for i in range(n):
		r[i] += p[i].count('.')
	for j in range(m):
		for i in range(n):
			if p[i][j] == '.':
				c[j] += 1
	np = [[m + n] * m] * n
	mini = m + n
	for i in range(n):
		for j in range(m):
			np[i][j] = r[i] + c[j]
			if p[i][j] == '.':
				np[i][j] -= 1
			mini = min(mini, np[i][j])
	print(mini)


import sys

def fun(a):
	qq = [0] * len(a)
	ww = [0] * len(a[0])
	for i in range(len(a)):
		for ii in range(len(a[i])):
			if a[i][ii] == '*':
				qq[i] += 1
				ww[ii] += 1
	mx1 = max(qq)
	mx2 = max(ww)
	ans = len(a) + len(a[0]) - mx1 - mx2
	for i in range(len(qq)):
		for ii in range(len(ww)):
			if qq[i] == mx1 and ww[ii] == mx2 and (a[i][ii] == '.'):
				ans -= 1
				return ans
	return ans

def qweq():
	inp = sys.stdin.read().split('\n')
	n = int(inp[0])
	ind = 0
	for i in range(n):
		ind += 1
		(tn, tm) = list(map(int, inp[ind].split()))
		answer = []
		for j in range(tn):
			ind += 1
			answer.append(inp[ind])
		print(fun(answer))
qweq()


def found_ans(matrix, n, m):
	weight_line = [0 for i in range(n)]
	weight_coll = [0 for j in range(m)]
	for i in range(n):
		for j in range(m):
			if matrix[i][j]:
				weight_line[i] += 1
				weight_coll[j] += 1
	(max_weight, x, y) = (-1, -1, -1)
	for i in range(n):
		for j in range(m):
			weight = weight_line[i] + weight_coll[j]
			if matrix[i][j]:
				weight -= 1
			if max_weight < weight:
				(max_weight, x, y) = (weight, i, j)
	return n + m - 1 - max_weight
q = int(input())
for qq in range(q):
	(n, m) = [int(i) for i in input().split()]
	matrix = []
	for i in range(n):
		matrix.append([True if j == '*' else False for j in input()])
	print(found_ans(matrix, n, m))


import sys
import math

def inp():
	p = sys.stdin.readline()
	return p
for _ in range(int(inp())):
	(n, m) = list(map(int, inp().split()))
	p = [str(inp()) for i in range(n)]
	q = []
	r = [0] * m
	c = 0
	for i in range(n):
		s = 0
		for j in range(m):
			if p[i][j] == '.':
				a = 1
			if p[i][j] == '*':
				a = 0
			r[j] = r[j] + a
			s = s + a
		q.append(s)
	k = float('inf')
	for i in range(n):
		for j in range(m):
			cost = q[i] + r[j]
			if p[i][j] == '.':
				cost = cost - 1
			k = min(k, cost)
	print(k)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	arr = [None] * n
	mc = 0
	arr1 = []
	rs = [0] * n
	cs = [0] * m
	for i in range(n):
		arr[i] = list(input())
		for j in range(m):
			if arr[i][j] == '*':
				rs[i] += 1
				cs[j] += 1
	minmoves = n + m - 1
	for i in range(n):
		for j in range(m):
			if arr[i][j] == '.':
				minmoves = min(minmoves, n - rs[i] + m - cs[j] - 1)
			else:
				minmoves = min(minmoves, n - rs[i] + m - cs[j])
	print(minmoves)


t = int(input())
for i in range(t):
	A = input()
	A = A.split()
	(n, m) = (int(A[0]), int(A[1]))
	R = [[0 for x in range(m)] for y in range(n)]
	P = [[0 for x in range(m)] for y in range(n)]
	for i in range(n):
		w = input()
		w.split()
		R[i] = w
	for i in range(n):
		for j in range(m):
			if R[i][j] == '*':
				P[i][j] = 1
	sumas_r = [0 for i in range(n)]
	for i in range(n):
		sumas_r[i] = sum((P[i][j] for j in range(m)))
	sumas_c = [0 for i in range(m)]
	for j in range(m):
		sumas_c[j] = sum((P[i][j] for i in range(n)))
	for i in range(n):
		for j in range(m):
			P[i][j] += m - sumas_r[i] + (n - sumas_c[j]) - 1
	minimo = 999999999999
	for i in range(n):
		for j in range(m):
			if P[i][j] <= minimo:
				minimo = P[i][j]
	print(minimo)


q = int(input())
while q > 0:
	q -= 1
	(n, m) = map(int, input().split())
	a = [[0 for i in range(m)] for j in range(n)]
	for i in range(n):
		b = input()
		for j in range(m):
			a[i][j] = b[j]
	row = [0 for i in range(n)]
	column = [0 for i in range(m)]
	for i in range(n):
		for j in range(m):
			if a[i][j] == '.':
				row[i] += 1
				column[j] += 1
	mini = n + m
	for i in range(n):
		for j in range(m):
			value = row[i] + column[j]
			if a[i][j] == '.':
				value -= 1
			mini = min(value, mini)
	print(mini)


import sys
q = int(input())
for qi in range(q):
	(n, m) = map(int, input().split())
	cc = []
	rc = []
	a = []
	for i in range(n):
		row = input()
		rc.append(row.count('*'))
		a.append(row)
	for j in range(m):
		cc.append(0)
		for i in range(n):
			cc[-1] += 1 if a[i][j] == '*' else 0
	res = m * n
	for i in range(n):
		for j in range(m):
			rij = m - rc[i] + n - cc[j]
			rij -= 1 if a[i][j] == '.' else 0
			res = min(res, rij)
	print(res)


import sys
import math as mt
import collections as cc
input = sys.stdin.readline
I = lambda : list(map(int, input().split()))
for tc in range(int(input())):
	(n, m) = I()
	a = [input().strip() for i in range(n)]
	row = [0] * n
	col = [0] * m
	rc = cc.defaultdict(int)
	for i in range(n):
		for j in range(m):
			if a[i][j] == '.':
				row[i] += 1
				col[j] += 1
			else:
				rc[i, j] += 1
	ans = n + m
	for i in range(n):
		for j in range(m):
			ans = min(ans, row[i] + col[j] - (a[i][j] == '.'))
	print(ans)


q = int(input())
print_list = []
for i in range(q):
	(n, m) = [int(c) for c in input().split()]
	rows = [0] * n
	cols = [0] * m
	data = []
	for j in range(n):
		row = input()
		data.append(row)
		for k in range(m):
			if row[k] == '.':
				rows[j] += 1
				cols[k] += 1
	min_sum = 1000000
	for j in range(n):
		for k in range(m):
			curr_sum = rows[j] + cols[k]
			if curr_sum <= min_sum:
				if data[j][k] == '.':
					min_sum = curr_sum - 1
				else:
					min_sum = curr_sum
	print_list.append(min_sum)
for el in print_list:
	print(el)


def mp():
	return map(int, input().split())
t = int(input())
for tt in range(t):
	(n, m) = mp()
	s = [input() for i in range(n)]
	mm = [m] * m
	nn = [n] * n
	for i in range(n):
		for j in range(m):
			nn[i] -= int(s[i][j] == '*')
			mm[j] -= int(s[i][j] == '*')
	ans = 10 ** 9
	for i in range(n):
		for j in range(m):
			ans = min(ans, nn[i] + mm[j] - (s[i][j] == '.' and nn[i] + mm[j] != 0))
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = []
	r = [0] * n
	c = [0] * m
	for i in range(n):
		a.append(list(input()))
		for j in range(m):
			if a[i][j] == '.':
				r[i] += 1
				c[j] += 1
	ans = int(1e+20)
	for i in range(n):
		for j in range(m):
			cur = r[i] + c[j]
			if a[i][j] == '.':
				cur -= 1
			ans = min(ans, cur)
	print(ans)


import math
x = input()
x = int(x)
for i in range(x):
	L = []
	y = list(map(int, input().split()))
	R = []
	C = []
	flag = 0
	for j in range(y[0]):
		L.append(input())
		R.append(0)
		for k in range(y[1]):
			if L[j][k] == '.':
				R[j] = R[j] + 1
	for j in range(y[1]):
		C.append(0)
		for k in range(y[0]):
			if L[k][j] == '.':
				C[j] = C[j] + 1
	Rmin = min(R)
	Cmin = min(C)
	Rmx = []
	Cmx = []
	for j in range(y[0]):
		if R[j] == Rmin:
			Rmx.append(j)
	for j in range(y[1]):
		if C[j] == Cmin:
			Cmx.append(j)
	for k in Rmx:
		for j in Cmx:
			if L[k][j] == '.' and flag != 1:
				print(Cmin + Rmin - 1)
				flag = 1
	if flag != 1:
		print(Cmin + Rmin)


kGfqVsLBCvIMEKU = range
kGfqVsLBCvIMEKr = int
kGfqVsLBCvIMEKe = input
kGfqVsLBCvIMEKo = map
kGfqVsLBCvIMEKJ = list
kGfqVsLBCvIMEKm = zip
kGfqVsLBCvIMEKR = min
kGfqVsLBCvIMEKY = print
for _ in kGfqVsLBCvIMEKU(kGfqVsLBCvIMEKr(kGfqVsLBCvIMEKe())):
	(n, m) = kGfqVsLBCvIMEKo(kGfqVsLBCvIMEKr, kGfqVsLBCvIMEKe().split())
	kGfqVsLBCvIMEKD = [kGfqVsLBCvIMEKJ(kGfqVsLBCvIMEKe()) for _ in kGfqVsLBCvIMEKU(n)]
	kGfqVsLBCvIMEKd = kGfqVsLBCvIMEKJ(kGfqVsLBCvIMEKm(*kGfqVsLBCvIMEKD))
	kGfqVsLBCvIMEKt = [kGfqVsLBCvIMEKD[i].count('.') for i in kGfqVsLBCvIMEKU(n)]
	kGfqVsLBCvIMEKP = [kGfqVsLBCvIMEKd[i].count('.') for i in kGfqVsLBCvIMEKU(m)]
	kGfqVsLBCvIMEKQ = 2147483647
	for y in kGfqVsLBCvIMEKU(n):
		for x in kGfqVsLBCvIMEKU(m):
			kGfqVsLBCvIMEKg = kGfqVsLBCvIMEKt[y] + kGfqVsLBCvIMEKP[x] - (1 if kGfqVsLBCvIMEKD[y][x] == '.' else 0)
			kGfqVsLBCvIMEKQ = kGfqVsLBCvIMEKR(kGfqVsLBCvIMEKQ, kGfqVsLBCvIMEKg)
	kGfqVsLBCvIMEKY(kGfqVsLBCvIMEKQ)


from sys import stdin, stdout

def rsingle_int():
	return int(stdin.readline().rstrip())

def rmult_int():
	return [int(x) for x in stdin.readline().rstrip().split()]

def rmult_str():
	return stdin.readline().rstrip().split()

def r_str():
	return stdin.readline().rstrip()

def rsingle_char():
	return stdin.read(1)

def eq_tile(one, two):
	return one[0] == two[0] and one[1] == two[1]

def main():
	q = rsingle_int()
	for i in range(q):
		(n, m) = rmult_int()
		pic = []
		for i in range(n):
			pic.append(r_str())
		inter_cols = []
		min_col_paint = n
		for j in range(m):
			cnt_not_paint = n
			for i in range(n):
				if pic[i][j] == '*':
					cnt_not_paint -= 1
			if cnt_not_paint < min_col_paint:
				min_col_paint = cnt_not_paint
				inter_cols.clear()
				inter_cols.append(j)
			elif cnt_not_paint == min_col_paint:
				inter_cols.append(j)
		inter_rows = []
		min_row_paint = m
		for i in range(n):
			cnt_not_paint = m
			for j in range(m):
				if pic[i][j] == '*':
					cnt_not_paint -= 1
			if cnt_not_paint < min_row_paint:
				min_row_paint = cnt_not_paint
				inter_rows.clear()
				inter_rows.append(i)
			elif cnt_not_paint == min_row_paint:
				inter_rows.append(i)
		min = min_row_paint + min_col_paint
		if min > 0:
			found = False
			for row in inter_rows:
				for col in inter_cols:
					if pic[row][col] == '.':
						found = True
						break
				if found:
					break
			if found:
				min -= 1
		print(min)
main()


T = input()
T = int(T)
for i in range(T):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	count_col = [0 for _ in range(m)]
	count_row = [0 for _ in range(n)]
	matrix = []
	for r in range(n):
		char_input = input()
		matrix.append(char_input)
		for j in range(len(char_input)):
			char = char_input[j]
			if char == '*':
				count_row[r] += 1
				count_col[j] += 1
	full = m + n - 1
	best = m + n - 1
	for r in range(n):
		for c in range(m):
			cnt = count_row[r] + count_col[c]
			if matrix[r][c] == '*':
				cnt -= 1
			left = full - cnt
			best = min(best, left)
	print(best)


request_count = int(input())
for request in range(request_count):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	matrix = []
	for y in range(n):
		matrix.append(list(input()))
	column = []
	rid = []
	for x in range(len(matrix)):
		rid.append(matrix[x].count('.'))
	for i in range(m):
		count = 0
		for x in range(len(matrix)):
			if matrix[x][i] == '.':
				count += 1
		column.append(count)
	ans = 0
	answer = n * m
	for x in range(len(rid)):
		for y in range(len(column)):
			ans = rid[x] + column[y]
			if matrix[x][y] == '.':
				ans -= 1
			if ans < answer:
				answer = ans
	print(answer)


from collections import *

def solve():
	(row, col, ans) = (defaultdict(int), defaultdict(int), float('inf'))
	for i in range(n):
		for j in range(m):
			if maze[i][j] == '.':
				row[i] += 1
				col[j] += 1
	for i in range(n):
		for j in range(m):
			tem = row[i] + col[j]
			if maze[i][j] == '.' or tem >= n + m:
				tem -= 1
			ans = min(ans, tem)
	return ans
for i in range(int(input())):
	(n, m) = map(int, input().split())
	maze = [input() for j in range(n)]
	print(solve())


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		x = input()
		a.append(x)
	X = []
	Y = []
	for i in range(n):
		c = 0
		for j in range(m):
			if a[i][j] == '.':
				c += 1
		X.append(c)
	D = m * n * 10
	for i in range(m):
		c = 0
		for j in range(n):
			if a[j][i] == '.':
				c += 1
		Y.append(c)
	for i in range(n):
		for j in range(m):
			if a[i][j] == '.':
				D = min(D, X[i] + Y[j] - 1)
			else:
				D = min(D, X[i] + Y[j])
	print(D)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = []
	for i in range(n):
		s.append(input())
	row = [0] * n
	col = [0] * m
	for i in range(n):
		for j in range(m):
			if s[i][j] == '.':
				row[i] += 1
				col[j] += 1
	pnt = m + n
	for i in range(n):
		for j in range(m):
			pnt = min(pnt, row[i] + col[j] - (s[i][j] == '.'))
	print(pnt)


import sys
input = sys.stdin.readline

def main():
	q = int(input())
	for t in range(q):
		(n, m) = map(int, input().split())
		white = {}
		white_in_row = [0] * n
		white_in_col = [0] * m
		for r in range(n):
			row = list(input())
			for (i, c) in enumerate(row):
				if c == '.':
					white[r, i] = True
					white_in_row[r] += 1
					white_in_col[i] += 1
		ans = n * m
		for x in range(n):
			for y in range(m):
				ans = min(ans, white_in_row[x] + white_in_col[y] - (1 if (x, y) in white else 0))
		print(ans)
main()


Input = lambda : map(int, input().split())
for i in range(int(input())):
	(n, m) = Input()
	row = [0 for k in range(n)]
	column = [0 for k in range(m)]
	st = list()
	for j in range(n):
		s = input()
		st.append(s)
		for k in range(m):
			if s[k] == '*':
				row[j] += 1
				column[k] += 1
	Min = float('inf')
	for ii in range(n):
		for jj in range(m):
			if st[ii][jj] == '*':
				Moshtarak = 1
			else:
				Moshtarak = 0
			yy = n + m - 1 - (row[ii] + column[jj] - Moshtarak)
			if yy < Min:
				Min = yy
			Moshtarak = 0
	print(Min)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	a = []
	for __ in range(n):
		a.append(input())
	nn = []
	for i in range(n):
		here = 0
		for j in range(m):
			if a[i][j] == '*':
				here += 1
		nn.append(here)
	mm = []
	for j in range(m):
		here = 0
		for i in range(n):
			if a[i][j] == '*':
				here += 1
		mm.append(here)
	ans = 0
	for i in range(n):
		for j in range(m):
			cur = nn[i] + mm[j]
			if a[i][j] == '*':
				cur -= 1
			ans = min(ans, -cur)
	ans += n + m - 1
	print(str(ans))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	row = [0] * n
	col = [0] * m
	t = [[] for _ in range(n)]
	for i in range(n):
		st = input()
		for j in range(len(st)):
			t[i].append(st[j])
			if st[j] == '.':
				row[i] += 1
				col[j] += 1
	s = n + m - 1
	for i in range(n):
		for j in range(m):
			s = min(s, row[i] + col[j] - (t[i][j] == '.'))
	print(s)


n = int(input())
t = 0
for t in range(n):
	a = list(map(int, input().split()))
	mp = []
	i = 0
	for i in range(a[0]):
		x = input()
		mp.insert(i, x)
	i = 0
	mpx = []
	mpy = []
	for i in range(a[0]):
		j = 0
		mpx.insert(i, 0)
		for j in range(a[1]):
			if mp[i][j] == '.':
				mpx[i] = mpx[i] + 1
	i = 0
	for i in range(a[1]):
		j = 0
		mpy.insert(i, 0)
		for j in range(a[0]):
			if mp[j][i] == '.':
				mpy[i] = mpy[i] + 1
	ans = 100000000
	i = 0
	for i in range(a[0]):
		j = 0
		for j in range(a[1]):
			ans1 = mpx[i] + mpy[j]
			if mp[i][j] == '.':
				ans1 = ans1 - 1
			ans = min(ans, ans1)
	print(ans)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	S = [str(input()) for _ in range(n)]
	R = [0] * n
	C = [0] * m
	for i in range(n):
		for j in range(m):
			if S[i][j] == '*':
				R[i] += 1
				C[j] += 1
	ans = 10 ** 18
	for i in range(n):
		for j in range(m):
			if S[i][j] == '*':
				temp = n - R[i] + m - C[j]
			else:
				temp = n - R[i] + m - C[j] - 1
			ans = min(ans, temp)
	print(ans)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	l = []
	countrow = []
	countcolumn = [0 for i in range(m)]
	mrow = 0
	for i in range(n):
		s = input()
		ll = []
		for c in range(len(s)):
			if s[c] == '.':
				ll.append(0)
			else:
				ll.append(1)
				countcolumn[c] += 1
		l.append(ll)
		ss = sum(ll)
		if ss > mrow:
			mrow = ss
		countrow.append(ss)
	mcolumn = max(countcolumn)
	flag = 0
	for i in range(n):
		for j in range(m):
			if countrow[i] == mrow and countcolumn[j] == mcolumn and (l[i][j] == 0):
				flag = 1
				break
		if flag == 1:
			break
	if flag == 1:
		print(n + m - max(countcolumn) - max(countrow) - 1)
	else:
		print(n + m - max(countcolumn) - max(countrow))


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	cols = [0] * m
	rows = [0] * n
	a = [[None] * m for _ in range(n)]
	for i in range(n):
		s = input()
		for j in range(m):
			cols[j] += s[j] == '.'
			rows[i] += s[j] == '.'
			a[i][j] = s[j]
	t = m + n - 1
	for i in range(n):
		for j in range(m):
			if a[i][j] == '.':
				t = min(t, cols[j] + rows[i] - 1)
			else:
				t = min(t, cols[j] + rows[i])
	print(t)


q = int(input())
for i in range(q):
	(n, m) = tuple([int(x) for x in input().split()])
	g = []
	for i in range(n):
		x = input()
		g.append(list(x))
	row = [0 for i in range(n)]
	col = [0 for i in range(m)]
	(k1, k2) = ([], [])
	for i in range(n):
		for j in range(m):
			if g[i][j] == '.':
				row[i] += 1
				col[j] += 1
	min = n + m
	for i in range(n):
		for j in range(m):
			x = row[i] + col[j] - (0 if g[i][j] == '*' else 1)
			if min > x:
				min = x
	print(min)


import os

def _f(n, m, matr):
	c_matr = []
	for i in range(n):
		c_matr.append(matr[i].count('*'))
	c_matr_t = [0] * m
	for i in range(n):
		for j in range(m):
			c_matr_t[j] += int(matr[i][j] == '*')
	max_w = 0
	for i in range(n):
		max_w = max(c_matr[i], max_w)
	w_arr = []
	for i in range(n):
		if c_matr[i] == max_w:
			w_arr.append(i)
	max_h = 0
	for i in range(m):
		max_h = max(c_matr_t[i], max_h)
	h_arr = []
	for i in range(m):
		if c_matr_t[i] == max_h:
			h_arr.append(i)
	f = False
	for i in w_arr:
		for j in h_arr:
			if matr[i][j] == '.':
				f = True
				break
		if f:
			break
	return n - max_h + m - max_w - int(f)

def f(n, m, matr):
	return _f(n, m, matr)
if os.environ.get('DEBUG', False):
	pass
else:
	q = int(input())
	for _ in range(q):
		(n, m) = list(map(int, input().split()))
		matr = []
		for i in range(n):
			matr.append(input())
		print(f(n, m, matr))


def main():
	(n, m) = map(int, input().split())
	arry = [0] * m
	arrx = [0] * n
	mat = []
	for i in range(n):
		string = str(input())
		mat.append(string)
		cnt = 0
		for j in range(m):
			if string[j] == '.':
				cnt += 1
				arry[j] += 1
		arrx[i] = cnt
	ans = n + m + 100
	for i in range(n):
		for j in range(m):
			temp = arrx[i] + arry[j]
			if mat[i][j] == '.':
				temp -= 1
			ans = min(ans, temp)
	print(ans)
	return

def test():
	t = int(input())
	while t:
		main()
		t -= 1
test()


q = int(input())
for req in range(q):
	(n, m) = map(int, input().split())
	array = [input() for i in range(n)]
	max_x = max(array, key=lambda x: x.count('*')).count('*')
	x_array = set()
	for (i, x) in enumerate(array):
		if x.count('*') == max_x:
			x_array.add(i)
	min_c = 1000000000000
	for i in range(m):
		count = m - max_x
		pr = True
		for j in range(n):
			if array[j][i] == '.':
				if j in x_array and pr:
					pr = False
				else:
					count += 1
		if count < min_c:
			min_c = count
	print(min_c)


def divisorGenerator(n):
	for i in range(1, int(n / 2 + 1)):
		if n % i == 0:
			yield i
	yield n

def divisorGen(n):
	factors = list(factorGenerator(n))
	nfactors = len(factors)
	f = [0] * nfactors
	while True:
		yield reduce(lambda x, y: x * y, [factors[x][0] ** f[x] for x in range(nfactors)], 1)
		i = 0
		while True:
			f[i] += 1
			if f[i] <= factors[i][1]:
				break
			f[i] = 0
			i += 1
			if i >= nfactors:
				return
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	c = [0 for i in range(m)]
	d = []
	l = []
	for i in range(n):
		a = input()
		l.append(a)
		d.append(a.count('*'))
		for j in range(m):
			if a[j] == '*':
				c[j] += 1
	c1 = max(c)
	d1 = max(d)
	c2 = []
	d2 = []
	for i in range(m):
		if c[i] == c1:
			c2.append(i)
	for i in range(n):
		if d[i] == d1:
			d2.append(i)
	if c1 == m and d1 == n:
		print(0)
	else:
		ans = 0
		for i in d2:
			for j in c2:
				if l[i][j] == '.':
					ans = 1
					break
			if ans == 1:
				break
		print(m + n - c1 - d1 - ans)

def divisorGenerator(n):
	large_divisors = []
	for i in range(1, int(math.sqrt(n) + 1)):
		if n % i == 0:
			yield i
			if i * i != n:
				large_divisors.append(int(n / i))
	for divisor in reversed(large_divisors):
		yield divisor

def s(n):
	if n == 1 or n == 2:
		return n
	elif n == 3:
		return 4
	else:
		return s(n - 1) + s(n - 2) + s(n - 3)

def divisors(n):
	factors = {}
	nn = n
	i = 2
	while i * i <= nn:
		while nn % i == 0:
			factors[i] = factors.get(i, 0) + 1
			nn //= i
		i += 1
	if nn > 1:
		factors[nn] = factors.get(nn, 0) + 1
	primes = list(factors.keys())

	def generate(k):
		if k == len(primes):
			yield 1
		else:
			rest = generate(k + 1)
			prime = primes[k]
			for factor in rest:
				prime_to_i = 1
				for _ in range(factors[prime] + 1):
					yield (factor * prime_to_i)
					prime_to_i *= prime
	for factor in generate(0):
		yield factor


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	pict = [input() for i in range(n)]
	x = []
	for d in range(n):
		x.append(pict[d].count('*'))
	y = [0 for d in range(m)]
	for j in range(m):
		for d in range(n):
			y[j] += pict[d][j] == '*'
	xm = max(x)
	ym = max(y)
	checkx = []
	checky = []
	for d in range(n):
		if x[d] == xm:
			checkx.append(d)
	for d in range(m):
		if y[d] == ym:
			checky.append(d)
	for a in checkx:
		for b in checky:
			if pict[a][b] == '.':
				print(n + m - ym - xm - 1)
				break
		else:
			continue
		break
	else:
		print(n + m - ym - xm)


def gns():
	return list(map(int, input().split()))
t = int(input())

def one():
	(n, m) = gns()
	mp = []
	ns = [0] * n
	ms = [0] * m
	for i in range(n):
		mp.append(input())
		for j in range(m):
			if mp[-1][j] == '*':
				ns[i] += 1
				ms[j] += 1
	min_n = max(ns)
	min_m = max(ms)
	min_ns = set([i for i in range(n) if ns[i] == min_n])
	min_ms = set([i for i in range(m) if ms[i] == min_m])
	ans = n - min_n + m - min_m
	for i in min_ns:
		for j in min_ms:
			if mp[i][j] == '.':
				print(ans - 1)
				return
	print(ans)
for i in range(t):
	one()


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	max_row = -1
	row_cand = []
	max_cols = [0] * m
	arr = []
	for i in range(n):
		s = input()
		arr.append(s)
		cnd = len([x for x in s if x == '*'])
		if cnd > max_row:
			row_cand = [i]
			max_row = cnd
		elif cnd == max_row:
			row_cand.append(i)
		max_row = max(max_row, len([x for x in s if x == '*']))
		for j in range(m):
			if s[j] == '*':
				max_cols[j] += 1
	max_col = max(max_cols)
	col_cand = []
	for i in range(m):
		if max_cols[i] == max_col:
			col_cand.append(i)
	found = False
	for r in row_cand:
		for c in col_cand:
			if arr[r][c] == '.':
				found = True
				break
		if found:
			break
	if found:
		print(n - max_row + m - max_col - 1)
	else:
		print(n - max_row + m - max_col)


import operator
from functools import reduce

def prod(factors):
	return reduce(operator.mul, factors, 1)

def answer():
	(H, W) = map(int, input().split())
	goal = H + W - 1
	val_map = [[0 if elm == '.' else 1 for elm in input()] for i in range(H)]
	for hi in range(H):
		cur = sum(val_map[hi])
		if hi == 0:
			max_h_val = cur
			max_h_indexs = [0]
		elif cur > max_h_val:
			max_h_val = cur
			max_h_indexs = [hi]
		elif cur == max_h_val:
			max_h_indexs.append(hi)
	for wi in range(W):
		cur = sum([val_map[hi][wi] for hi in range(H)]) - prod([val_map[hi][wi] for hi in max_h_indexs])
		if wi == 0:
			max_w_val = cur
		elif cur > max_w_val:
			max_w_val = cur
	max_ = max_h_val + max_w_val
	out = goal - max_
	return out
q = int(input())
for _ in range(q):
	out = answer()
	print(out)


for _ in range(int(input())):
	(m, n) = list(map(int, input().strip().split(' ')))
	grid = []
	for i in range(m):
		grid += [input()]
	row = []
	col = []
	MIN_row = 10 ** 10
	MIN_col = 10 ** 10
	for i in range(m):
		count = 0
		for j in range(n):
			if grid[i][j] == '.':
				count += 1
		row += [count]
		MIN_row = min(MIN_row, count)
	for j in range(n):
		count = 0
		for i in range(m):
			if grid[i][j] == '.':
				count += 1
		col += [count]
		MIN_col = min(MIN_col, count)
	want_row = set([])
	for i in range(len(row)):
		if row[i] == MIN_row:
			want_row.add(i)
	want_col = set([])
	for i in range(len(col)):
		if col[i] == MIN_col:
			want_col.add(i)
	flag = 0
	for i in range(len(row)):
		if flag == 1:
			break
		for j in range(len(col)):
			if grid[i][j] == '.':
				if i in want_row and j in want_col:
					flag = 1
					break
	print(MIN_row + MIN_col - flag)


import sys
import math
from collections import defaultdict, Counter
input = sys.stdin.readline

def print_(x):
	sys.stdout.write(str(x) + ' ')

def rInt():
	return int(input())

def rList():
	arr = input().split()
	return arr

def cInt(arr):
	res = []
	for itr in arr:
		res.append(int(itr))
	return res

def pList(arr):
	for _ in arr:
		print_(_)
test_cases = rInt()
for test_case in range(test_cases):
	inp = rList()
	n = int(inp[0])
	m = int(inp[1])
	mat = []
	s = ''
	for row in range(n):
		s = input()
		mat.append(s)
	rowC = []
	colC = []
	for row in mat:
		cnt = 0
		for _ in row:
			if _ == '.':
				cnt += 1
		rowC.append(cnt)
	for col in range(m):
		cnt = 0
		for row in mat:
			if row[col] == '.':
				cnt += 1
		colC.append(cnt)
	rC = 0
	ans = 10 ** 6
	for row in mat:
		for cC in range(m):
			cnt = rowC[rC] + colC[cC]
			if row[cC] == '.':
				cnt -= 1
			ans = min(ans, cnt)
		rC += 1
	print(ans)


q = int(input())
for i in range(q):
	[n, m] = [int(w) for w in input().split()]
	obr = n * [None]
	for x in range(n):
		obr[x] = list(input())
	r_pocty_ciernych = n * [None]
	for x in range(n):
		ciernych = 0
		for y in range(m):
			if obr[x][y] == '*':
				ciernych += 1
		r_pocty_ciernych[x] = ciernych
	najviac_r = max(r_pocty_ciernych)
	s_pocty_ciernych = m * [None]
	for y in range(m):
		ciernych = 0
		for x in range(n):
			if obr[x][y] == '*':
				ciernych += 1
		s_pocty_ciernych[y] = ciernych
	najviac_s = max(s_pocty_ciernych)
	najcernejsie_r = []
	for x in range(n):
		if r_pocty_ciernych[x] == najviac_r:
			najcernejsie_r.append(x)
	najcernejsie_s = []
	for y in range(m):
		if s_pocty_ciernych[y] == najviac_s:
			najcernejsie_s.append(y)
	uspesne = False
	for j in najcernejsie_r:
		if uspesne:
			break
		for k in najcernejsie_s:
			if obr[j][k] == '.':
				uspesne = True
				break
	if uspesne:
		print(m + n - najviac_r - najviac_s - 1)
	else:
		print(m + n - najviac_r - najviac_s)


q = int(input())
for query in range(q):
	(n, m) = [int(i) for i in input().split()]
	painting = []
	for row in range(n):
		painting.append(list(input()))
	rowScores = [0] * n
	colScores = [0] * m
	for row in range(n):
		rowScores[row] = painting[row].count('.')
		for col in range(m):
			if painting[row][col] == '.':
				colScores[col] += 1
	minBuckets = n + m - 1
	maxRow = 0
	maxCol = 0
	for row in range(n):
		for col in range(m):
			center = painting[row][col]
			val = rowScores[row] + colScores[col] - 1
			if center == '*':
				val += 1
			if val < minBuckets:
				minBuckets = val
				maxRow = row
				maxCol = col
	print(minBuckets)


def readInts():
	return [int(c) for c in input().split(' ')]

def solve():
	(n, m) = readInts()
	cells = [input() for _ in range(n)]
	maxR = 0
	rs = []
	for r in range(n):
		count = 0
		for c in range(m):
			if cells[r][c] == '*':
				count += 1
		if count > maxR:
			maxR = count
			rs = []
		if count == maxR:
			rs.append(r)
	maxC = 0
	cs = []
	for c in range(m):
		count = 0
		for r in range(n):
			if cells[r][c] == '*':
				count += 1
		if count > maxC:
			maxC = count
			cs = []
		if count == maxC:
			cs.append(c)
	ans = n - maxR + (m - maxC)
	for r in rs:
		for c in cs:
			if cells[r][c] == '.':
				return ans - 1
	return ans

def main():
	Q = readInts()[0]
	for q in range(Q):
		print(solve())
main()


q = int(input())
for w in range(q):
	(n, m) = map(int, input().split())
	I = [m] * n
	J = [n] * m
	A = [[''] * m for i in range(n)]
	for i in range(n):
		A[i] = list(input())
		for j in range(m):
			if A[i][j] == '*':
				I[i] -= 1
				J[j] -= 1
	ans = 10 ** 9 + 7
	for i in range(n):
		for j in range(m):
			if A[i][j] == '.':
				ans = min(ans, I[i] + J[j] - 1)
			else:
				ans = min(ans, I[i] + J[j])
	print(ans)


for _ in [0] * int(input()):
	(n, m) = map(int, input().split())
	s = [input() for _ in range(n)]
	a = [0] * n
	b = [0] * m
	for i in range(n):
		for j in range(m):
			if s[i][j] == '*':
				a[i] += 1
				b[j] += 1
	ans = 0
	for i in range(n):
		for j in range(m):
			ans = max(ans, a[i] + b[j] - (s[i][j] == '*'))
	print(n + m - 1 - ans)


n = int(input())
for i in range(0, n):
	(r, c) = list(map(int, input().split()))
	a = []
	for j in range(0, r):
		a.append(input())
	m = r + c
	p = []
	q = []
	for j in range(0, r):
		p.append(a[j].count('.'))
	for k in range(0, c):
		s = 0
		for j in range(0, r):
			if a[j][k] == '.':
				s += 1
		q.append(s)
	m = r + c
	for j in range(0, r):
		for k in range(0, c):
			s = p[j] + q[k]
			if a[j][k] == '.':
				s = s - 1
			if s < m:
				m = s
	print(m)


from collections import defaultdict

def handle(matrix, m, n):
	(rows, cols) = (defaultdict(int), defaultdict(int))
	for i in range(m):
		for j in range(n):
			if matrix[i][j] == '*':
				rows[i] += 1
				cols[j] += 1
	if not rows:
		ans = m + n - 1
	else:
		max_rows = max(rows.values())
		max_cols = max(cols.values())
		ans = m + n - max_rows - max_cols
		candidates = ((i, j) for i in range(m) for j in range(n) if rows[i] == max_rows and cols[j] == max_cols)
		for (i, j) in candidates:
			if matrix[i][j] == '.':
				ans -= 1
				break
	print(ans)

def main():
	nc = int(input())
	for _ in range(nc):
		(m, n) = map(int, input().split())
		matrix = [input() for _ in range(m)]
		handle(matrix, m, n)
main()


for _ in range(int(input())):
	(n, M) = map(int, input().split())
	m = 0
	Mat = []
	for i in range(n):
		l = list(input())
		c = l.count('*')
		if c > m:
			m = c
		Mat.append(l)
	m1 = 0
	ans = 0
	for i in range(M):
		c = 0
		for j in range(n):
			if Mat[j][i] == '*':
				c += 1
		if c > m1:
			m1 = c
			col = i
	Col = []
	for i in range(M):
		c = 0
		for j in range(n):
			if Mat[j][i] == '*':
				c += 1
		if c == m1:
			Col.append(i)
	for i in range(n):
		if Mat[i].count('*') == m:
			for j in Col:
				if Mat[i][j] != '*':
					ans = -1
					break
			if ans == -1:
				break
	ans += n - m + M - m1
	print(ans)


t = int(input())
for i in range(t):
	(n, m) = map(int, input().split())
	row = [0 for k in range(n)]
	col = [0 for k in range(m)]
	mat = []
	for j in range(n):
		l = list(input())
		mat.append(l)
		for k in range(m):
			if l[k] == '.':
				row[j] += 1
				col[k] += 1
	minimum = n * m
	for j in range(n):
		for k in range(m):
			if mat[j][k] == '.':
				val = row[j] + col[k] - 1
				if val < minimum:
					minimum = val
			else:
				val = row[j] + col[k]
				if val < minimum:
					minimum = val
	print(minimum)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	grid = [input() for y in range(n)]
	(rowStars, colStars) = ([], [])
	for x in range(n):
		rowStars.append(grid[x].count('*'))
	for y in range(m):
		temp = ''
		for x in range(n):
			temp += grid[x][y]
		colStars.append(temp.count('*'))
	ans = n + m - 1
	for x in range(n):
		for y in range(m):
			temp = n + m - 1 - (rowStars[x] + colStars[y])
			if grid[x][y] == '*':
				temp += 1
			ans = min(ans, temp)
	print(ans)


def func():
	(n, m) = map(int, input().split())
	matrix = [input() for i in range(n)]
	stroka = [n for i in range(n)]
	stolb = [m for i in range(m)]
	for i in range(n):
		for j in range(m):
			if matrix[i][j] == '*':
				stroka[i] -= 1
				stolb[j] -= 1
	ans = 10 ** 12
	for i in range(n):
		for j in range(m):
			x = stroka[i] + stolb[j]
			if matrix[i][j] == '.':
				x -= 1
			if x < ans:
				ans = x
	return ans
q = int(input())
for i in range(q):
	print(func())


t = int(input())
for y in range(t):
	(n, m) = map(int, input().split())
	x = []
	rowindex = -1
	colindex = -1
	r = -1
	rows = []
	for i in range(n):
		x += [input()]
		cnt = x[-1].count('*')
		if cnt > r:
			rowindex = i
			r = cnt
			rows = [i]
		elif cnt == r:
			rows += [i]
	c = -1
	cols = []
	for i in range(m):
		count = 0
		for j in range(n):
			if x[j][i] == '*':
				count += 1
		if count > c:
			c = count
			colindex = i
			cols = [i]
		elif count == c:
			cols += [i]
	ans = m * n + 1
	flag = 0
	for i in rows:
		for j in cols:
			if x[i][j] == '.':
				flag = 1
	print(n + m - r - c - flag)


q = int(input())
anss = [''] * q
for ians in range(q):
	(n, m) = map(int, input().split())
	rows = [[]] * n
	for i in range(n):
		rows[i] = list(input())
	cols = list(zip(*rows))
	row_max = max(map(lambda s: s.count('*'), rows))
	col_max = max(map(lambda s: s.count('*'), cols))
	row_i = []
	for (i, s) in enumerate(rows):
		if s.count('*') == row_max:
			row_i.append(i)
	col_j = []
	for (j, s) in enumerate(cols):
		if s.count('*') == col_max:
			col_j.append(j)
	b = False
	for i in row_i:
		s = rows[i]
		for j in col_j:
			if s[j] != '*':
				b = True
				break
	ans = n - row_max + (m - col_max)
	if b:
		ans -= 1
	anss[ians] = ans
for ans in anss:
	print(ans)


import sys
import math
import collections
import operator as op
from collections import deque
from math import gcd, inf, sqrt, pi, cos, sin, ceil, log2, floor, log
from bisect import bisect_right, bisect_left, bisect
from functools import reduce
from sys import stdin, stdout, setrecursionlimit
setrecursionlimit(2 ** 20)

def ncr(n, r):
	r = min(r, n - r)
	numer = reduce(op.mul, range(n, n - r, -1), 1)
	denom = reduce(op.mul, range(1, r + 1), 1)
	return numer // denom

def prime_factors(n):
	i = 2
	factors = []
	while i * i <= n:
		if n % i:
			i += 1
		else:
			n //= i
			factors.append(i)
	if n > 1:
		factors.append(n)
	return list(factors)

def isPowerOfTwo(x):
	return x and (not x & x - 1)
MOD = 1000000007
PMOD = 998244353
N = 10 ** 6
LOGN = 30
alp = 'abcdefghijklmnopqrstuvwxyz'
T = 1
T = int(stdin.readline())
for _ in range(T):
	(n, m) = list(map(int, stdin.readline().rstrip().split()))
	a = []
	for i in range(n):
		s = list(stdin.readline().strip('\n'))
		a.append(s)
	for i in range(n):
		for j in range(m):
			if a[i][j] == '*':
				a[i][j] = 1
			else:
				a[i][j] = 0
	r = [0] * n
	c = [0] * m
	for i in range(n):
		for j in range(m):
			r[i] += a[i][j] == 0
			c[j] += a[i][j] == 0
	ans = n + m - 1
	for i in range(n):
		for j in range(m):
			ans = min(ans, r[i] + c[j] - int(a[i][j] == 0))
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	A = [0] * n
	row = [0] * n
	column = [0] * m
	for i in range(n):
		A[i] = input()
		sum1 = 0
		sum2 = 0
		for k in range(m):
			if A[i][k] == '*':
				row[i] += 1
				column[k] += 1
	mini = 0
	for i in range(n):
		for j in range(m):
			if A[i][j] == '.':
				if row[i] + column[j] > mini:
					mini = row[i] + column[j]
			elif row[i] + column[j] - 1 > mini:
				mini = row[i] + column[j] - 1
	print(m + n - 1 - mini)


def minim(a):
	smallest = min(a)
	return (smallest, [index for (index, element) in enumerate(a) if smallest == element])

def remove_1(inds_r, inds_c, matrix):
	for i in inds_r:
		for j in inds_c:
			if matrix[i][j] == '.':
				return -1
	return 0
T = int(input())
for l in range(T):
	(n, m) = [int(i) for i in input().strip().split(' ')]
	row_counts = [0 for i in range(n)]
	col_counts = [0 for i in range(m)]
	matrix = [input().strip() for x in range(n)]
	for i in range(n):
		for j in range(m):
			if matrix[i][j] == '.':
				row_counts[i] += 1
				col_counts[j] += 1
	(col, inds_c) = minim(col_counts)
	(row, inds_r) = minim(row_counts)
	result = col + row
	if result == 0:
		print(result)
	else:
		print(result + remove_1(inds_r, inds_c, matrix))


import copy
q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	a = []
	for j in range(n):
		s = input()
		a.append(s)
	b = []
	c = []
	for j in range(n):
		count = 0
		for k in range(m):
			if a[j][k] == '*':
				count = count + 1
		b.append(count)
	for j in range(m):
		count = 0
		for k in range(n):
			if a[k][j] == '*':
				count = count + 1
		c.append(count)
	maxx = 0
	for j in range(n):
		for k in range(m):
			if a[j][k] == '*':
				if b[j] + c[k] - 1 > maxx:
					maxx = b[j] + c[k] - 1
			elif b[j] + c[k] > maxx:
				maxx = b[j] + c[k]
	print(n + m - maxx - 1)


q = int(input())
for k in range(q):
	(n, m) = (int(i) for i in input().split())
	a = [input() for i in range(n)]
	row = [0] * n
	col = [0] * m
	for i in range(n):
		for j in range(m):
			if a[i][j] == '.':
				row[i] += 1
				col[j] += 1
	_min = n * m
	for i in range(n):
		for j in range(m):
			if a[i][j] == '.':
				_min = min(_min, row[i] + col[j] - 1)
			else:
				_min = min(_min, row[i] + col[j])
	print(_min)


from collections import Counter
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	x = [input() for _ in range(n)]
	y = [list(v) for v in zip(*x)]
	mx = m
	ix = []
	for (i, v) in enumerate(x):
		mm = Counter(v)['.']
		if mm < mx:
			mx = mm
			ix = [i]
		elif mm == mx:
			ix.append(i)
	my = n
	iy = []
	for (i, v) in enumerate(y):
		mm = Counter(v)['.']
		if mm < my:
			my = mm
			iy = [i]
		elif mm == my:
			iy.append(i)
	fnd = False
	for i in ix:
		for k in iy:
			if x[i][k] == '.':
				fnd = True
				break
		if fnd:
			break
	print(mx + my - 1 if fnd else mx + my)


from itertools import product
transform = lambda c: 1 if c == '*' else 0

def argmax_all(a):
	sum_of_row = [sum(a) for a in a]
	m = max(sum_of_row)
	return (m, [i for (i, e) in enumerate(sum_of_row) if e == m])
q = int(input())
for _ in range(q):
	(n, m) = map(int, input().strip().split())
	a = []
	for _ in range(n):
		a.append(list(map(transform, list(input().strip()))))
	(max_row, row_indexes) = argmax_all(a)
	(max_col, col_indexes) = argmax_all(zip(*a))
	ans = n - max_col + m - max_row
	for (r, c) in product(row_indexes, col_indexes):
		if a[r][c] == 0:
			ans -= 1
			break
	print(ans)


t = int(input())

def res(arr, r, c):
	m = float('Inf')
	q = [[0 for i in range(c)] for j in range(r)]
	black_col = [0] * c
	black_row = [0] * r
	for row in range(r):
		for col in range(c):
			st = arr[row]
			if st[col] == '*':
				q[row][col] = 1
				black_col[col] += 1
				black_row[row] += 1
	for row in range(r):
		for col in range(c):
			if q[row][col] == 1:
				m = min(m, r - black_row[row] + (c - black_col[col]))
			else:
				m = min(m, r - black_row[row] + (c - black_col[col]) - 1)
	return m
for i in range(t):
	nm = list(map(int, input().split()))
	a = []
	for j in range(nm[0]):
		a.append(input())
	print(res(a, nm[0], nm[1]))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.append(input())
	r = []
	(mr, ir) = (0, 0)
	rowcount = []
	columncount = []
	for i in range(n):
		count = 0
		for j in a[i]:
			if j == '*':
				count += 1
		rowcount.append(count)
	(mc, ic) = (0, 0)
	for i in range(m):
		count = 0
		for j in range(n):
			if a[j][i] == '*':
				count += 1
		columncount.append(count)
	ans = n * m
	for i in range(n):
		for j in range(m):
			tans = m - rowcount[i] + n - columncount[j]
			if a[i][j] == '.':
				tans -= 1
			ans = min(ans, tans)
	print(ans)


from sys import stdin
a = int(stdin.readline())
for A in range(0, a):
	pan = list()
	c = -1
	(m, n) = (int(i) for i in stdin.readline().split())
	garo = list((0 for i in range(0, m)))
	sero = list((0 for i in range(0, n)))
	for M in range(0, m):
		line = stdin.readline()
		pan.append(line)
		for N in range(0, n):
			if line[N] == '*':
				garo[M] += 1
				sero[N] += 1
	for M in range(0, m):
		for N in range(0, n):
			if pan[M][N] == '*':
				tiles = garo[M] + sero[N] - 1
			else:
				tiles = garo[M] + sero[N]
			if tiles > c:
				c = tiles
	print(m + n - 1 - c)


t = int(input())
while t != 0:
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	s = [input() for _ in range(n)]
	a = [0] * n
	b = [0] * m
	an = 0
	for i in range(n):
		for j in range(m):
			if s[i][j] == '*':
				a[i] += 1
				b[j] += 1
	for i in range(n):
		for j in range(m):
			an = max(an, a[i] + b[j] - (s[i][j] == '*'))
	print(n + m - 1 - an)
	t -= 1


for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	ro = [[0 for _ in range(m)] for _ in range(n)]
	col = [m] * m
	row = [n] * n
	for i in range(n):
		for (j, c) in enumerate(input()):
			if c == '*':
				col[j] -= 1
				row[i] -= 1
			else:
				ro[i][j] = -1
	res = n + m
	for (i, r) in enumerate(row):
		for (j, c) in enumerate(col):
			res = min(res, r + c + ro[i][j])
	print(res)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	s = []
	for i in range(n):
		s.append(input())
	row = []
	col = []
	for i in range(n):
		row.append(s[i].count('*'))
	for i in range(m):
		cnt = 0
		for j in range(n):
			if s[j][i] == '*':
				cnt += 1
		col.append(cnt)
	a = [[None] * m] * n
	ans = n + m
	for i in range(n):
		for j in range(m):
			ans = min(ans, n + m - 1 - row[i] - col[j] + int(bool(s[i][j] == '*')))
	print(ans)


import math
from decimal import *
import random
mod = int(1000000000.0) + 7
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	gd = [[0] for i in range(n)]
	for i in range(n):
		gd[i] = list(input())
	mrk = [[0 for i in range(m)] for i in range(n)]
	for i in range(n):
		cnt = 0
		for j in range(m):
			if gd[i][j] == '.':
				cnt += 1
		for x in range(m):
			mrk[i][x] += cnt
	ans = int(mod)
	for i in range(m):
		cnt = 0
		for j in range(n):
			if gd[j][i] == '.':
				cnt += 1
		for x in range(n):
			ans = min(ans, mrk[x][i] + cnt + (-1 if gd[x][i] == '.' else 0))
	print(ans)


M = 10 ** 9 + 7
R = lambda : map(int, input().split())
n = int(input())
for i in range(n):
	(n, m) = R()
	L = [[0 for i in range(m)] for j in range(n)]
	a = []
	for i in range(n):
		a.append(input())
	for i in range(n):
		c = 0
		for j in range(m):
			if a[i][j] == '.':
				c += 1
		for j in range(m):
			L[i][j] = c
	for i in range(m):
		c = 0
		for j in range(n):
			if a[j][i] == '.':
				c += 1
		for j in range(n):
			L[j][i] += c
	mi = 10 ** 9
	k = []
	for i in range(n):
		for j in range(m):
			mi = min(mi, L[i][j])
	for i in range(n):
		for j in range(m):
			if L[i][j] == mi and a[i][j] == '.':
				mi -= 1
	print(mi)


from sys import stdin
q = int(stdin.readline())
for _ in range(q):
	(n, m) = [int(x) for x in stdin.readline().split()]
	matrix = []
	min_row = m
	min_col = n
	for i in range(n):
		matrix.append([c for c in stdin.readline().strip()])
		missing_row = sum((c != '*' for c in matrix[i]))
		min_row = min(min_row, missing_row)
	candidates_row = set()
	for i in range(n):
		missing_row = sum((c != '*' for c in matrix[i]))
		if min_row == missing_row:
			candidates_row.add(i)
	for j in range(m):
		missing_col = sum((matrix[i][j] != '*' for i in range(n)))
		if any((matrix[i][j] != '*' and i in candidates_row for i in range(n))):
			missing_col -= 1
		min_col = min(min_col, missing_col)
	print(min_row + min_col)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	arr = [input() for i in range(n)]
	x = set()
	x_sum = -1
	for i in range(m):
		new_sum = sum((arr[j][i] == '*' for j in range(n)))
		if x_sum < new_sum:
			x = {i}
			x_sum = new_sum
		elif x_sum == new_sum:
			x.add(i)
	y = set()
	y_sum = -1
	for j in range(n):
		new_sum = sum((arr[j][i] == '*' for i in range(m)))
		if y_sum < new_sum:
			y = {j}
			y_sum = new_sum
		elif y_sum == new_sum:
			y.add(j)
	if '.' not in [arr[j][i] for j in y for i in x]:
		print(m + n - x_sum - y_sum)
	else:
		print(m + n - x_sum - y_sum - 1)


import sys

def main():
	q = int(input())
	for _ in range(q):
		[m, n] = list(map(int, input().split()))
		A = [list(input()) for i in range(m)]
		R = {}
		C = {}
		maxCol = 0
		maxRow = 0
		tr = -1
		tc = -1
		for i in range(m):
			for j in range(n):
				if A[i][j] == '*':
					if i in R:
						R[i] += 1
					else:
						R[i] = 1
					if j in C:
						C[j] += 1
					else:
						C[j] = 1
					if R[i] > maxRow:
						maxRow = R[i]
						tr = i
					if C[j] > maxCol:
						maxCol = C[j]
						tc = j
		final = sys.maxsize
		for i in range(m):
			for j in range(n):
				if i not in R:
					R[i] = 0
				if j not in C:
					C[j] = 0
				temp = n - R[i] + m - C[j]
				if A[i][j] == '.':
					temp -= 1
				final = min(final, temp)
		print(final)
main()


class Read:

	@staticmethod
	def int():
		return int(input())

	@staticmethod
	def list(sep=' '):
		return input().split(sep)

	@staticmethod
	def list_int(sep=' '):
		return list(map(int, input().split(sep)))

def main():
	(n, m) = Read.list_int()
	s = []
	max_x_index = []
	max_y_index = []
	max_x_count = 0
	max_y_count = 0
	for j in range(n):
		s.append(input())
		count = s[j].count('*')
		if count > max_x_count:
			max_x_count = count
			max_x_index = [j]
		elif count == max_x_count:
			max_x_index.append(j)
	for j in range(m):
		count = 0
		for h in range(n):
			if s[h][j] == '*':
				count += 1
		if count > max_y_count:
			max_y_count = count
			max_y_index = [j]
		elif count == max_y_count:
			max_y_index.append(j)
	res = n - max_x_count + (m - max_y_count)
	if res == 0:
		print(0)
		return
	for y in max_y_index:
		for x in max_x_index:
			if s[x][y] == '.':
				print(res - 1)
				return
	print(res)
t = Read.int()
for i in range(t):
	main()


t = int(input())
while t:
	t = t - 1
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	a = []
	for i in range(n):
		a.append(list(map(str, input())))
	dp1 = [0] * n
	dp2 = [0] * m
	for i in range(n):
		b = 0
		for j in range(m):
			if a[i][j] == '*':
				b = b + 1
		dp1[i] = b
	for i in range(m):
		b = 0
		for j in range(n):
			if a[j][i] == '*':
				b = b + 1
		dp2[i] = b
	dp_max = []
	for i in range(len(dp1)):
		for j in range(len(dp2)):
			if a[i][j] == '*':
				x = n + m - 1 - (dp1[i] + dp2[j] - 1)
				dp_max.append(x)
			else:
				x = n + m - 1 - (dp1[i] + dp2[j])
				dp_max.append(x)
	print(min(dp_max))


q = int(input())
for _ in range(q):
	(n, m) = [int(x) for x in input().split()]
	lst = [[0 for i in range(m)] for j in range(n)]
	for i in range(n):
		s = input()
		for j in range(m):
			lst[i][j] = s[j]
	row = [0 for i in range(n)]
	column = [0 for i in range(m)]
	for i in range(n):
		for j in range(m):
			if lst[i][j] == '.':
				row[i] += 1
				column[j] += 1
	result = n + m
	for i in range(n):
		for j in range(m):
			val = row[i] + column[j]
			if lst[i][j] == '.':
				val -= 1
			result = min(result, val)
	print(result)


import sys, math

def read_int():
	return int(sys.stdin.readline().strip())

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

def read_string():
	return sys.stdin.readline().strip()

def read_string_list(delim=' '):
	return sys.stdin.readline().strip().split(delim)

def print_list(l, delim=' '):
	print(delim.join(map(str, l)))
q = read_int()
for _ in range(q):
	(n, m) = read_int_list()
	grid = []
	for i in range(n):
		grid.append(read_string())
	rows = [0 for i in range(n)]
	cols = [0 for j in range(m)]
	for i in range(n):
		for j in range(m):
			if grid[i][j] == '*':
				rows[i] += 1
				cols[j] += 1
	ans = float('inf')
	for i in range(n):
		for j in range(m):
			ans = min(ans, n + m - 1 - (rows[i] + cols[j] - (1 if grid[i][j] == '*' else 0)))
	print(ans)


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	rows = []
	cols = []
	inpL = []
	for i in range(n):
		row = list(str(input()))
		rows.append(row.count('.'))
		inpL.append(row)
	ans = n + m - 1
	for i in range(m):
		cur = 0
		for j in range(n):
			if inpL[j][i] == '.':
				cur += 1
		for j in range(n):
			if inpL[j][i] == '.':
				ans = min(ans, rows[j] + cur - 1)
			else:
				ans = min(ans, rows[j] + cur)
	print(ans)


import sys
input = sys.stdin.readline
t = int(input())
for i in range(t):
	matrix = []
	l = list(map(int, input().split()))
	n = l[0]
	m = l[1]
	for j in range(n):
		temp = input()
		yo = []
		for k in range(m):
			yo.append(temp[k])
		matrix.append(yo)
	stars = []
	for j in range(n):
		ans = 0
		for k in range(m):
			if matrix[j][k] == '*':
				ans += 1
		stars.append(ans)
	max1 = max(stars)
	stars1 = []
	for j in range(m):
		ans = 0
		for k in range(n):
			if matrix[k][j] == '*':
				ans += 1
		stars1.append(ans)
	max2 = max(stars1)
	tuple1 = []
	for j in range(len(stars)):
		for k in range(len(stars1)):
			if matrix[j][k] == '.' and stars[j] == max1 and (stars1[k] == max2):
				tuple1.append((j, k))
	result = 0
	if len(tuple1) == 0:
		result = n + m - (max1 + max2)
	else:
		j1 = tuple1[0][0]
		k1 = tuple1[0][1]
		result = n + m - (stars[j1] + stars1[k1]) - 1
	print(result)


for _ in range(int(input())):
	(row, col) = [int(x) for x in input().split()]
	grid = [[x for x in input()] for _ in range(row)]
	(rowc, colc) = ([0] * row, [0] * col)
	for i in range(row):
		for j in range(col):
			if grid[i][j] == '*':
				rowc[i] += 1
				colc[j] += 1
	ans = int(1e+19)
	for i in range(row):
		for j in range(col):
			k = rowc[i] + colc[j] - (grid[i][j] == '*')
			ans = min(row + col - 1 - k, ans)
	print(ans)


def handle(arr, n, m):
	(rows, cols) = ([0] * n, [0] * m)
	for i in range(n):
		for j in range(m):
			if arr[i][j]:
				rows[i] += 1
				cols[j] += 1
	min_c = 1000000
	for i in range(n):
		for j in range(m):
			a = 1 if arr[i][j] else 0
			min_c = min(min_c, rows[i] + cols[j] - a)
	return min_c
q = int(input())
for _ in range(q):
	(n, m) = input().split()
	(m, n) = (int(m), int(n))
	arr = []
	for i in range(n):
		arr.append(list(map(lambda x: True if x == '.' else False, input())))
	print(handle(arr, n, m))


n = int(input())
for i in range(n):
	ans = 1000000
	penality = 0
	(r, c) = map(int, input().split())
	a = [input() for j in range(r)]
	row = [0] * r
	col = [0] * c
	for j in range(r):
		for k in range(c):
			if a[j][k] == '.':
				row[j] += 1
				col[k] += 1
	for j in range(r):
		for k in range(c):
			if a[j][k] == '.':
				penalty = 1
			else:
				penalty = 0
			temp = row[j] + col[k] - penalty
			if temp < ans:
				ans = temp
	print(ans)


import sys
q = int(sys.stdin.readline().strip())
for t in range(0, q):
	(n, m) = list(map(int, sys.stdin.readline().strip().split()))
	L = []
	R = [0] * n
	C = [0] * m
	for i in range(0, n):
		L.append(sys.stdin.readline().strip())
		for j in range(0, m):
			if L[i][j] != '*':
				R[i] = R[i] + 1
				C[j] = C[j] + 1
	ans = n + m - 1
	for i in range(0, n):
		for j in range(0, m):
			x = 0
			if L[i][j] != '*':
				x = -1
			ans = min([ans, R[i] + C[j] + x])
	print(ans)


T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(input())
	mr = n + m
	r = []
	for i in range(n):
		s = 0
		for j in range(m):
			if l[i][j] == '.':
				s += 1
		if mr > s:
			mr = s
			r = [i]
		elif mr == s:
			r.append(i)
	c = []
	mc = n + m
	for i in range(m):
		s = 0
		for j in range(n):
			if l[j][i] == '.':
				s += 1
		if mc > s:
			mc = s
			c = [i]
		elif mc == s:
			c.append(i)
	flag = 0
	for i in r:
		for j in c:
			if l[i][j] == '.':
				flag = 1
				break
		if flag == 1:
			break
	print(mr + mc - flag)


import sys, atexit
from io import BytesIO
inp = BytesIO(sys.stdin.buffer.read())
input = lambda : inp.readline().decode('ascii')
buf = BytesIO()
sys.stdout.write = lambda s: buf.write(s.encode('ascii'))
atexit.register(lambda : sys.__stdout__.buffer.write(buf.getvalue()))
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	A = [input() for _ in range(n)]
	At = [''.join(a) for a in zip(*A)]
	mxr = -1
	maxrow = []
	for (i, a) in enumerate(A):
		cnt = a.count('*')
		if cnt > mxr:
			mxr = cnt
			maxrow = []
		if cnt == mxr:
			maxrow.append(i)
	mxc = -1
	maxcol = []
	for (i, a) in enumerate(At):
		cnt = a.count('*')
		if cnt > mxc:
			mxc = cnt
			maxcol = []
		if cnt == mxc:
			maxcol.append(i)
	saved = 0
	for i in maxcol:
		for j in maxrow:
			if A[j][i] == '.':
				saved = 1
	print(n + m - (mxc + mxr) - saved)


t = int(input())
for i in range(t):
	(e, s) = list(map(int, input().split()))
	f = []
	for h in range(e):
		f.append(input())
	now = 0
	mi = 0
	mi2 = []
	g = []
	for y in range(e):
		now = 0
		g = []
		for x in range(s):
			if f[y][x] == '*':
				now += 1
			else:
				g.append(x)
		if now > mi:
			mi = now
			mi2 = []
			for k in range(len(g)):
				mi2.append(g[k])
		elif now == mi:
			for k in range(len(g)):
				mi2.append(g[k])
	now = 0
	ma = 0
	d = True
	for y in range(s):
		now = 0
		for x in range(e):
			if f[x][y] == '*':
				now += 1
		if now > ma:
			ma = now
			if y in mi2:
				d = False
			else:
				d = True
		elif now == ma:
			if y in mi2:
				d = False
	if d:
		print(e - mi + s - ma)
	else:
		print(e - mi + s - ma - 1)


q = int(input())
for Q in range(q):
	(n, m) = list(map(int, input().split()))
	arr = []
	for i in range(n):
		t = input()
		arr.append(t)
	max_m = 0
	max_n = 0
	ind_m = []
	ind_n = []
	for i in range(n):
		temp_m = 0
		for j in range(m):
			if arr[i][j] == '*':
				temp_m += 1
		if temp_m > max_m:
			max_m = temp_m
			ind_n = []
		if temp_m == max_m:
			ind_n.append(i)
	for i in range(m):
		temp_n = 0
		for j in range(n):
			if arr[j][i] == '*':
				temp_n += 1
		if temp_n > max_n:
			max_n = temp_n
			ind_m = []
		if temp_n == max_n:
			ind_m.append(i)
	s = n - max_n + m - max_m
	p = False
	for i in ind_m:
		for j in ind_n:
			if arr[j][i] == '.':
				p = True
				break
	if p == True:
		s -= 1
	print(s)


for _ in range(int(input())):
	(r, c) = map(int, input().split())
	b = []
	max1 = -999
	max2 = -999
	flag = 0
	row = []
	col = []
	for i in range(r):
		s = str(input())
		b.append(s)
		if max1 < s.count('*'):
			max1 = s.count('*')
			row = []
		if max1 == s.count('*'):
			row.append(i)
	for i in range(c):
		count = 0
		for j in range(r):
			if b[j][i] == '*':
				count += 1
		if max2 < count:
			max2 = count
			col = []
		if max2 == count:
			col.append(i)
	for i in range(len(row)):
		for j in range(len(col)):
			if b[row[i]][col[j]] == '.':
				flag = 1
				break
	if flag == 1:
		print(c - max1 + (r - max2) - 1)
	else:
		print(c - max1 + (r - max2))


import math
a = int(input())
for i in range(a):
	(n, m) = map(int, input().split())
	ans = []
	row = []
	for i in range(n):
		s = input()
		gam = []
		for i in range(len(s)):
			gam.append(s[i])
		ans.append(gam)
		row.append(s.count('.'))
	col = []
	for i in range(m):
		cnt = 0
		for j in range(n):
			if ans[j][i] == '.':
				cnt += 1
		col.append(cnt)
	mini = math.inf
	for i in range(n):
		for j in range(m):
			if ans[i][j] == '.':
				mini = min(mini, row[i] + col[j] - 1)
			else:
				mini = min(mini, row[i] + col[j])
	print(mini)


qs = []
nm = []
Q = int(input())
for _ in range(Q):
	(n, m) = map(int, input().split())
	qs.append([[0 if a == '.' else 1 for a in list(input())] for _ in range(n)])
	nm.append([n, m])
for q in range(Q):
	state = qs[q]
	(n, m) = nm[q]
	rowm = []
	for k in range(n):
		rowm.append(sum(state[k]))
	colm = []
	for k in range(m):
		com = 0
		for i in range(n):
			com += state[i][k]
		colm.append(com)
	rowmax = max(rowm)
	colmax = max(colm)
	ans = n + m - rowmax - colmax
	rinds = [i for (i, x) in enumerate(rowm) if x == rowmax]
	cinds = [i for (i, x) in enumerate(colm) if x == colmax]
	cross = False
	for r in rinds:
		for c in cinds:
			if state[r][c] == 0:
				cross = True
				break
	if cross:
		ans -= 1
	print(ans)


for t in range(int(input())):
	(n, m) = map(int, input().split())
	a = [input() for i in range(n)]
	rows = [len([1 for j in range(m) if a[i][j] == '*']) for i in range(n)]
	cols = [len([1 for i in range(n) if a[i][j] == '*']) for j in range(m)]
	print(min([m + n - 1 - (rows[i] + cols[j] - (1 if a[i][j] == '*' else 0)) for i in range(n) for j in range(m)]))


T = int(input())
for _ in range(T):
	sec = input()
	tmp = sec.split(' ')
	(n, m) = (int(tmp[0]), int(tmp[1]))
	mp = ['' for _mp in range(n)]
	row = [0 for _row in range(n)]
	col = [0 for _col in range(m)]
	for ii in range(n):
		mp[ii] = input()
		for (idx, c) in enumerate(mp[ii]):
			if c == '*':
				row[ii] += 1
				col[idx] += 1
	ans = n + m - 1
	for i in range(n):
		for j in range(m):
			if mp[i][j] == '*':
				ans = min(ans, n + m - row[i] - col[j])
			else:
				ans = min(ans, n + m - 1 - row[i] - col[j])
	print(ans)


import sys

class cinn:

	def __init__(self):
		self.x = []

	def cin(self, t=int):
		if len(self.x) == 0:
			a = input()
			self.x = a.split()
			self.x.reverse()
		return self.get(t)

	def get(self, t):
		return t(self.x.pop())

	def clist(self, n, t=int):
		l = [0] * n
		for i in range(n):
			l[i] = self.cin(t)
		return l

	def clist2(self, n, t1=int, t2=int, t3=int, tn=2):
		l = [0] * n
		for i in range(n):
			if tn == 2:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				l[i] = (a1, a2)
			elif tn == 3:
				a1 = self.cin(t1)
				a2 = self.cin(t2)
				a3 = self.cin(t3)
				l[i] = (a1, a2, a3)
		return l

	def clist3(self, n, t1=int, t2=int, t3=int):
		return self.clist2(self, n, t1, t2, t3, 3)

	def cout(self, i, ans=''):
		if ans == '':
			print('Case #' + str(i + 1) + ':', end=' ')
		else:
			print('Case #' + str(i + 1) + ':', ans)

	def printf(self, thing):
		print(thing, end='')

	def countlist(self, l, s=0, e=None):
		if e == None:
			e = len(l)
		dic = {}
		for el in range(s, e):
			if l[el] not in dic:
				dic[l[el]] = 1
			else:
				dic[l[el]] += 1
		return dic

	def talk(self, x):
		print(x, flush=True)

	def dp1(self, k):
		L = [-1] * k
		return L

	def dp2(self, k, kk):
		L = [-1] * k
		for i in range(k):
			L[i] = [-1] * kk
		return L

	def isprime(self, n):
		if n == 1 or n == 0:
			return False
		for i in range(2, int(n ** 0.5 + 1)):
			if n % i == 0:
				return False
		return True

	def factors(self, n):
		from functools import reduce
		return set(reduce(list.__add__, ([i, n // i] for i in range(1, int(n ** 0.5) + 1) if n % i == 0)))

	def nthprime(self, n):
		i = 0
		s = 2
		L = []
		while i < n:
			while not self.isprime(s):
				s += 1
			L.append(s)
			s += 1
			i += 1
		return L

	def matrixin(self, m, n, t=int):
		L = []
		for i in range(m):
			p = self.clist(n, t)
			L.append(p)
		return L

	def seive(self, k):
		n = k + 1
		L = [True] * n
		L[1] = False
		L[0] = False
		for i in range(2, n):
			if L[i] == True:
				for j in range(2 * i, n, i):
					L[j] = False
		return L

	def seiven(self, n, L):
		i = 0
		for j in range(len(L)):
			if L[j] == True:
				i += 1
			if i == n:
				return j

	def matrixin2(self, m, t=int):
		L = []
		for i in range(m):
			iny = self.cin(str)
			lsmall = []
			for el in iny:
				lsmall.append(t(el))
			L.append(lsmall)
		return L
c = cinn()
x = c.cin()
for i in range(x):
	n = c.cin()
	m = c.cin()
	mat = c.matrixin2(n, str)
	minrows = []
	minle = m
	for row in range(n):
		mis = []
		for box in range(m):
			if mat[row][box] == '.':
				mis.append((row, box))
		if minle > len(mis):
			minrows = [mis]
			minle = len(mis)
		elif minle == len(mis):
			minrows.append(mis)
	mincol = []
	mincole = n
	for row in range(m):
		mis = []
		for box in range(n):
			if mat[box][row] == '.':
				mis.append((box, row))
		if mincole > len(mis):
			mincol = [mis]
			mincole = len(mis)
		elif mincole == len(mis):
			mincol.append(mis)
	dic = {}
	su = mincole + minle
	for el in minrows:
		for elly in el:
			dic[elly] = 1
	found = False
	for el in mincol:
		if found:
			break
		for elly in el:
			if elly in dic:
				print(su - 1)
				found = True
				break
	if not found:
		print(su)


from collections import Counter

def dox(arr):
	(n, m) = (len(arr), len(arr[0]))
	dp = [[None for i in range(m)] for j in range(n)]
	maxcount = 0
	maxind = []
	totdiff = 0
	for i in range(n):
		temp = Counter(arr[i])['*']
		if temp > maxcount:
			maxcount = temp
			maxind = [i]
		elif temp == maxcount:
			maxind.append(i)
	totdiff = n - maxcount
	for i in maxind:
		for j in range(len(arr[0])):
			dp[i][j] = 1
	maxcount = 0
	te = 1
	for i in range(0, m):
		temp = 0
		te = 1
		for j in range(0, n):
			if arr[j][i] == '*':
				temp += 1
			elif te and dp[j][i]:
				te = 0
				temp += 1
		if temp > maxcount:
			maxcount = temp
	return totdiff + m - maxcount

def doy(arr):
	(n, m) = (len(arr), len(arr[0]))
	dp = [[None for i in range(m)] for j in range(n)]
	maxcount = 0
	maxind = []
	totdiff = 0
	for i in range(0, m):
		temp = 0
		for j in range(0, n):
			if arr[j][i] == '*':
				temp += 1
		if temp > maxcount:
			maxcount = temp
			maxind = [i]
		elif temp == maxcount:
			maxind.append(i)
	for i in maxind:
		for j in range(n):
			dp[j][i] = m
	maxdiff = m - maxcount
	maxcount = 0
	te = 1
	for i in range(n):
		temp = 0
		te = 1
		for j in range(m):
			if arr[i][j] == '*':
				temp += 1
			elif te and dp[i][j] == len(arr[0]):
				te = 0
				temp += 1
		if temp > maxcount:
			maxcount = temp
	return maxdiff + n - maxcount
for _ in range(int(input())):
	(n, m) = list(map(int, input().split()))
	arr = []
	for i in range(n):
		s = input()
		arr.append(list(s))
	print(min(dox(arr), doy(arr)))


q = int(input())
for test in range(q):
	(n, m) = map(int, input().split())
	cntV = [0] * m
	cntH = [0] * n
	a = []
	for i in range(n):
		s = input()
		a.append(s)
		for j in range(len(s)):
			if s[j] == '.':
				cntV[j] += 1
				cntH[i] += 1
	best = n + m - 1
	for i in range(n):
		for j in range(m):
			t = cntV[j] + cntH[i]
			if a[i][j] == '.':
				t -= 1
			best = min(best, t)
	print(best)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	l = []
	r = []
	for i in range(n):
		x = input()
		r.append(x.count('.'))
		l.append(x)
	cl = []
	for i in range(m):
		c = 0
		for j in range(n):
			if l[j][i] == '.':
				c += 1
		cl.append(c)
	mx = n * m
	for i in range(n):
		for j in range(m):
			s = r[i] + cl[j]
			if l[i][j] == '.':
				s = s - 1
			mx = min(s, mx)
	print(mx)


t = int(input())
for _ in range(t):
	(n, m) = list(map(int, input().split()))
	a = []
	countr = [0] * n
	countc = [0] * m
	for i in range(n):
		s = list(input())
		a.append(s)
		for j in range(len(s)):
			if s[j] == '.':
				countr[i] += 1
				countc[j] += 1
	fans = 10000000000000.0
	for i in range(n):
		for j in range(m):
			ans = countr[i] + countc[j]
			if a[i][j] == '.':
				ans -= 1
			fans = min(fans, ans)
	print(int(fans))


from os import path
import sys, time
from math import ceil, floor, gcd, log, log2, factorial
from collections import defaultdict, Counter, deque
from itertools import permutations
maxx = float('inf')
I = lambda : int(sys.stdin.buffer.readline())
tup = lambda : map(int, sys.stdin.buffer.readline().split())
lint = lambda : [int(x) for x in sys.stdin.buffer.readline().split()]
S = lambda : sys.stdin.readline().replace('\n', '').strip()

def grid(r, c):
	return [lint() for i in range(r)]
stpr = lambda x: sys.stdout.write(f'{x}' + '\n')
star = lambda x: print(' '.join(map(str, x)))
localsys = 0
start_time = time.time()
if path.exists('input.txt'):
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	ar = [input() for _ in range(n)]
	(cn, cm) = ([0] * n, [0] * m)
	for i in range(n):
		for j in range(m):
			cn[i] += ar[i][j] == '.'
			cm[j] += ar[i][j] == '.'
	ans = n + m
	for i in range(n):
		for j in range(m):
			ans = min(ans, cn[i] + cm[j] - (ar[i][j] == '.'))
	print(ans)
if localsys:
	print('\n\nTime Elased :', time.time() - start_time, 'seconds')


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	nn = [0] * n
	mn = [0] * m
	S = []
	for _ in range(n):
		S.append(list(input()))
	for i in range(n):
		for j in range(m):
			if S[i][j] == '*':
				nn[i] += 1
				mn[j] += 1
	max_nn = max(nn)
	max_mn = max(mn)
	cross = False
	for i in range(n):
		for j in range(m):
			if nn[i] == max_nn and mn[j] == max_mn and (S[i][j] != '*'):
				cross = True
				break
		if cross:
			break
	if cross:
		print(n + m - max_nn - max_mn - 1)
	else:
		print(n + m - max_nn - max_mn)


import sys
input = sys.stdin.readline
n = int(input())
for i in range(n):
	(m, n) = map(int, input().split())
	a = []
	for j in range(m):
		b = input()
		c = []
		for j in b:
			c.append(j)
		a.append(c)
	l = 0
	d = []
	for j in range(n):
		q = 0
		for k in range(m):
			if a[k][j] == '*':
				q += 1
		if q > l:
			l = q
	u = []
	for j in range(n):
		q = 0
		for k in range(m):
			if a[k][j] == '*':
				q += 1
		if q == l:
			u.append(j)
	p = 0
	for j in range(m):
		q = 0
		for k in range(n):
			if a[j][k] == '*':
				q += 1
		if q > p:
			p = q
	h = []
	for j in range(m):
		q = 0
		for k in range(n):
			if a[j][k] == '*':
				q += 1
		if q == p:
			h.append(j)
	if m == 1:
		print(n - p)
	elif n == 1:
		print(m - l)
	else:
		v = 0
		for s in h:
			for o in u:
				if a[s][o] == '.':
					v = 1
					print(n - p + (m - l) - 1)
					break
			if v == 1:
				break
		if v == 0:
			print(n - p + (m - l))


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = []
	for x in range(n):
		k = list(input())
		a.append(k)
	min = m * n
	loc = 0
	row = n * [0]
	col = m * [0]
	for i in range(n):
		for j in range(m):
			if a[i][j] == '.':
				loc += 1
		row[i] = loc
		loc = 0
	for i in range(m):
		for j in range(n):
			if a[j][i] == '.':
				loc += 1
		col[i] = loc
		loc = 0
	for i in range(len(row)):
		for j in range(len(col)):
			if a[i][j] != '.':
				loc = row[i] + col[j]
			else:
				loc = row[i] + col[j] - 1
			if loc < min:
				min = loc
	print(min)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		k = list(input())
		l.append(k)
	lo = [0] * m
	(ans1, ans2) = (10 ** 18, 10 ** 18)
	for i in range(m):
		count = 0
		for j in range(n):
			if l[j][i] == '*':
				count += 1
		lo[i] += n - count
		ans2 = min(ans2, lo[i])
	for i in range(n):
		count = 0
		mini = -1
		for j in range(m):
			if l[i][j] != '*':
				pass
			else:
				count += 1
		ans1 = min(m - count, ans1)
	for i in range(n):
		count = 0
		mini = -1
		for j in range(m):
			if l[i][j] != '*':
				pass
			else:
				count += 1
		if m - count == ans1:
			for j in range(m):
				if l[i][j] != '*':
					ans2 = min(ans2, lo[j] - 1)
	print(ans1 + ans2)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = []
	for i in range(n):
		s.append(list(input()))
	cntn = [0] * n
	cntm = [0] * m
	for i in range(n):
		for j in range(m):
			cntn[i] += 1 if s[i][j] == '.' else 0
			cntm[j] += 1 if s[i][j] == '.' else 0
	ans = n + m
	for i in range(n):
		for j in range(m):
			ans = min(ans, cntn[i] + cntm[j] - (1 if s[i][j] == '.' else 0))
	print(ans)


for irt in range(int(input())):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(input())
	m2 = [0] * n
	m1 = [0] * m
	for i in range(n):
		c = 0
		for j in range(m):
			if l[i][j] == '.':
				c += 1
		m2[i] = c
	for i in range(m):
		c = 0
		for j in range(n):
			if l[j][i] == '.':
				c += 1
		m1[i] = c
	tot = 999999999999999999999
	for i in range(n):
		for j in range(m):
			r = 0
			if l[i][j] == '.':
				r = 1
			ans = m2[i] + m1[j] - r
			tot = min(tot, ans)
	print(tot)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	s = [input() for _ in range(n)]
	(cn, cm) = ([0] * n, [0] * m)
	for i in range(n):
		for j in range(m):
			cn[i] += s[i][j] == '.'
			cm[j] += s[i][j] == '.'
	ans = n + m
	for i in range(n):
		for j in range(m):
			ans = min(ans, cn[i] + cm[j] - (s[i][j] == '.'))
	print(ans)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	arr = []
	(row, col) = ([0 for i in range(n)], [0 for j in range(m)])
	for i in range(n):
		s = input()
		arr.append(s)
	for i in range(n):
		for j in range(m):
			if arr[i][j] == '.':
				row[i] += 1
				col[j] += 1
	total = m + n
	for i in range(n):
		for j in range(m):
			if arr[i][j] == '.':
				total = min(total, row[i] + col[j] - 1)
			else:
				total = min(total, row[i] + col[j])
	print(total)


q = int(input())
import math
for i in range(q):
	(n, m) = map(int, input().split())
	arr = []
	for j in range(n):
		t = input()
		arr.append(list(t))
	row = [0 for j in range(n)]
	for j in range(n):
		row[j] = arr[j].count('*')
	col = [0 for j in range(m)]
	for j in range(m):
		col[j] = 0
		for k in range(n):
			if arr[k][j] == '*':
				col[j] += 1
	req = math.inf
	for j in range(n):
		for k in range(m):
			if arr[j][k] == '.':
				rowc = row[j]
				colc = col[k]
				tmp = max(0, m + n - 1 - (rowc + colc))
				req = min(tmp, req)
			else:
				rowc = row[j]
				colc = col[k]
				tmp = max(0, m + n - 1 - (rowc + colc - 1))
				req = min(tmp, req)
	print(req)


from itertools import product
for i in range(int(input())):
	(n, m) = map(int, input().split())
	best = m + n - 1
	a = [input() for i in range(n)]
	row = [a[i].count('*') for i in range(n)]
	col = [sum((1 if a[i][j] == '*' else 0 for i in range(n))) for j in range(m)]
	for (x, y) in product(range(n), range(m)):
		best = min(best, m + n - 1 - row[x] - col[y] + (1 if a[x][y] == '*' else 0))
	print(best)


def solve():
	(n, m) = map(int, input().split())
	s = [input().strip() for i in range(n)]
	ans = list(map(lambda x: x.count('.'), s))
	ans2 = [0] * m
	for i in range(n):
		for j in range(m):
			if s[i][j] == '.':
				ans2[j] += 1
	mini = min(ans)
	minj = min(ans2)
	answ = mini + minj
	for i in range(n):
		if ans[i] != mini:
			continue
		for j in range(m):
			if s[i][j] == '.' and ans2[j] == minj:
				answ -= 1
				return print(answ)
	print(answ)
for _ in range(int(input())):
	solve()


q = int(input())
for t in range(q):
	(n, m) = list(map(int, input().split()))
	x = []
	row = [0] * n
	col = [0] * m
	for i in range(n):
		r = input()
		x.append(r)
		row[i] = 0
		for c in r:
			if c == '.':
				row[i] += 1
	for j in range(m):
		col[j] = 0
		for i in range(n):
			if x[i][j] == '.':
				col[j] += 1
	ans = n + m + 1
	for i in range(n):
		for j in range(m):
			M = row[i] + col[j]
			if x[i][j] == '.':
				M -= 1
			if M < ans:
				ans = M
	print(ans)


for _ in range(int(input().strip())):
	(n, m) = map(int, input().strip().split())
	grid = [list(input().strip()) for _ in range(n)]
	(row_counts, col_counts) = ([], [])
	for row in grid:
		row_counts.append(row.count('.'))
	for j in range(m):
		colcount = 0
		for i in range(n):
			if grid[i][j] == '.':
				colcount += 1
		col_counts.append(colcount)
	(min_rc, min_cc) = (min(row_counts), min(col_counts))
	ans = m + n
	for r in range(n):
		if row_counts[r] == min_rc:
			for c in range(m):
				if col_counts[c] == min_cc:
					curr_ans = min_rc + min_cc
					if grid[r][c] == '.':
						curr_ans -= 1
					ans = min(ans, curr_ans)
	print(ans)


def check(list):
	row = []
	col = []
	(n, m) = (len(list), len(list[0]))
	minimum = float('inf')
	for i in range(n):
		count = 0
		for j in range(m):
			if list[i][j] == '.':
				count += 1
		if count == minimum:
			row.append([i, count])
		if count < minimum:
			minimum = count
			row = [[i, count]]
	minimum = float('inf')
	for i in range(m):
		count = 0
		for j in range(n):
			if list[j][i] == '.':
				count += 1
		if count == minimum:
			col.append([i, count])
		if count < minimum:
			minimum = count
			col = [[i, count]]
	min = row[0][1] + col[0][1]
	for i in range(len(row)):
		for j in range(len(col)):
			if list[row[i][0]][col[j][0]] == '.':
				min -= 1
				return min
	return min
n = int(input())
for i in range(n):
	(a, b) = map(int, input().split())
	l = []
	for i in range(a):
		l.append(list(input()))
	print(check(l))


for i in range(0, int(input())):
	a = []
	cek = []
	for x in map(int, input().split()):
		a.append(x)
	for _ in range(0, a[0]):
		temp = list(input())
		cek.append(temp)
	row = {}
	col = {}
	for r in range(0, a[0]):
		for c in range(0, a[1]):
			if cek[r][c] == '*':
				if r in row:
					row[r] += 1
				else:
					row[r] = 1
				if c in col:
					col[c] += 1
				else:
					col[c] = 1
			else:
				if r in row:
					pass
				else:
					row[r] = 0
				if c in col:
					pass
				else:
					col[c] = 0
	starRow = max(row.values())
	starCol = max(col.values())
	listvalueR = list(row.values())
	listvalueC = list(col.values())
	iMaxR = []
	iMaxC = []
	for num in range(0, len(listvalueR)):
		if listvalueR[num] == starRow:
			iMaxR.append(num)
	for num in range(0, len(listvalueC)):
		if listvalueC[num] == starCol:
			iMaxC.append(num)
	if starRow == a[0] and starCol == a[1]:
		print(0)
	else:
		flag = False
		for k in range(0, len(iMaxR)):
			for l in range(0, len(iMaxC)):
				if cek[iMaxR[k]][iMaxC[l]] == '.':
					flag = True
		if flag:
			print(a[0] - starRow + (a[1] - starCol) - 1)
		else:
			print(a[0] - starRow + (a[1] - starCol))


T = int(input())
for i in range(T):
	(n, m) = list(map(int, input().split()))
	grid = []
	for i in range(n):
		grid.append(input())
	max_val = 0
	cols = []
	rows = []
	for col in range(m):
		val = 0
		for row in range(n):
			val += 1 if grid[row][col] == '*' else 0
		cols.append(val)
	for row in range(n):
		val = 0
		for col in range(m):
			val += 1 if grid[row][col] == '*' else 0
		rows.append(val)
	for row in range(n):
		for col in range(m):
			val = rows[row] + cols[col] - (1 if grid[row][col] == '*' else 0)
			max_val = max(max_val, val)
	ans = n + m - 1 - max_val
	print(ans)


q = int(input())
for _ in range(q):
	(n, m) = tuple(map(int, input().split()))
	rows = [0 for _ in range(n)]
	columns = [0 for _ in range(m)]
	board = list()
	min_change = n + m - 1
	for i in range(n):
		s = input()
		for j in range(m):
			if s[j] == '*':
				columns[j] += 1
				rows[i] += 1
		board.append(s)
	for i in range(n):
		for j in range(m):
			change = n + m - columns[j] - rows[i]
			if board[i][j] == '.':
				change -= 1
			min_change = min(min_change, change)
	print(min_change)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	rows = [[0] * m for _ in range(n)]
	cols = [[0] * n for _ in range(m)]
	for i in range(n):
		line = input()
		for j in range(m):
			if line[j] == '*':
				rows[i][j] = 1
				cols[j][i] = 1
	sum_r = [sum(rows[r]) for r in range(n)]
	sum_c = [sum(cols[c]) for c in range(m)]
	max_c = max(sum_c)
	max_r = max(sum_r)
	ans = n + m - (max_r + max_c)
	for i in range(n):
		if sum_r[i] < max_r:
			continue
		for j in range(m):
			if rows[i][j] == 0 and sum_c[j] == max_c:
				ans = n + m - (max_r + max_c) - 1
	print(ans)


q = int(input())
for _ in range(q):
	max1 = 0
	max2 = 0
	rows = []
	pos1 = []
	pos2 = []
	(n, m) = map(int, input().split())
	for i in range(n):
		row = input()
		count = row.count('*')
		rows.append(row)
		if max1 == count:
			pos1.append(i)
		elif max1 < count:
			pos1 = [i]
			max1 = count
	for i in range(m):
		count = 0
		for j in range(n):
			if rows[j][i] == '*':
				count += 1
		if max2 == count:
			pos2.append(i)
		elif max2 < count:
			pos2 = [i]
			max2 = count
	for i in pos1:
		for j in pos2:
			if rows[i][j] == '.':
				print(n - max1 + (m - max2) - 1)
				break
		else:
			continue
		break
	else:
		print(m - max1 + (n - max2))


q = input()
for i in range(int(q)):
	black = []
	inp = input()
	n = int(inp.split(' ')[0])
	m = int(inp.split(' ')[1])
	lists = [[] for x in range(m)]
	for j in range(n):
		a = input()
		black.append(0)
		mm = range(m)
		for k in mm:
			if a[k] == '*':
				black[j] += 1
				lists[k].append(1)
			else:
				lists[k].append(0)
	row = max(black)
	row_indices = [i for (i, x) in enumerate(black) if x == row]
	black_cols = [sum(s) for s in lists]
	col = max(black_cols)
	col_indices = [i for (i, x) in enumerate(black_cols) if x == col]
	minus_one = 0
	for l in row_indices:
		for k in col_indices:
			if lists[k][l] == 0:
				minus_one = 1
	res = n - row + m - col - minus_one
	print(res)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	l = [[0 for i in range(m)] for j in range(n)]
	x = list()
	y = [0] * m
	for i in range(n):
		d = 0
		c = input()
		for j in range(m):
			l[i][j] = c[j]
			if c[j] == '.':
				d += 1
				y[j] += 1
		x.append(d)
	s = 10000000000
	for i in range(n):
		for j in range(m):
			if x[i] + y[j] <= s:
				s = x[i] + y[j]
				if l[i][j] == '.':
					s -= 1
	print(s)


import sys
input = sys.stdin.readline
for _ in range(int(input())):
	(n, m) = list(map(int, input().split(' ')))
	q = []
	ma_row = 0
	ans = 60000000000000000000000
	ma_ind = []
	for i in range(n):
		x = input()
		z = x.count('*')
		if z == ma_row:
			ma_ind.append(i)
		elif z > ma_row:
			ma_ind = [i]
			ma_row = z
		q.append(x)
	ma_col = 0
	mc_ind = []
	for i in range(m):
		c = 0
		for j in range(n):
			if q[j][i] == '*':
				c += 1
		if c == ma_col:
			mc_ind.append(i)
		elif c > ma_col:
			mc_ind = [i]
			ma_col = c
	for i in ma_ind:
		for j in mc_ind:
			x = n - ma_row + m - ma_col
			if q[i][j] == '.':
				x -= 1
			ans = min(ans, x)
	print(ans)


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	b = []
	c = [0] * m
	r = [0] * n
	for j in range(n):
		b.append([0] * m)
	a = []
	for j in range(n):
		a.append(list(input()))
	for j in range(n):
		for k in range(m):
			if a[j][k] == '.':
				r[j] += 1
				c[k] += 1
				b[j][k] = -1
	min_dif = n * m
	for j in range(n):
		for k in range(m):
			min_dif = min(min_dif, r[j] + c[k] + b[j][k])
	print(min_dif)


query = int(input())

def cross(n, m):
	box = []
	colcol = [0 for iiii in range(m)]
	rowrow = [0 for iii in range(n)]
	max_row = 0
	flag = 0
	max_col = 0
	for i in range(n):
		box.append(list(input()))
		for j in range(m):
			if max_row == n and max_col == m:
				print(0)
				flag = 100
				break
			elif box[i][j] == '*':
				colcol[j] += 1
				rowrow[i] += 1
	if flag == 0:
		max_col = max(colcol)
		max_row = max(rowrow)
		maxrowpos = []
		maxcolpos = []
		rowindex = 0
		colindex = 0
		for term in rowrow:
			if term == max_row:
				maxrowpos.append(rowindex)
			rowindex += 1
		for term in colcol:
			if term == max_col:
				maxcolpos.append(colindex)
			colindex += 1
		to_print = m - max_col + n - max_row
		for ii in range(len(maxrowpos)):
			for jj in range(len(maxcolpos)):
				if box[maxrowpos[ii]][maxcolpos[jj]] == '.':
					to_print = m - max_col + n - max_row - 1
		print(to_print)
for k in range(query):
	nm = input().split()
	cross(int(nm[0]), int(nm[1]))


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	row = [0] * n
	col = [0] * m
	ar = []
	for i in range(n):
		li = list(input())
		ar.append(li)
		for j in range(m):
			if li[j] == '*':
				row[i] += 1
				col[j] += 1
	ans = n * m
	for i in range(n):
		for j in range(m):
			xx = m - row[i]
			xx += n - col[j]
			if ar[i][j] == '*':
				ans = min(ans, xx)
			else:
				ans = min(ans, xx - 1)
	print(ans)


def count_white(i, j):
	if picture[i][j] == 0:
		return row_cnt_white[i] + colomn_cnt_white[j] - 1
	return row_cnt_white[i] + colomn_cnt_white[j]
num_queries = int(input())
for _ in range(num_queries):
	(n, m) = map(int, input().split())
	row_cnt_white = [0 for i in range(n)]
	colomn_cnt_white = [0 for i in range(m)]
	picture = [[1 for j in range(m)] for i in range(n)]
	for i in range(n):
		row = input()
		for j in range(m):
			if row[j] == '.':
				row_cnt_white[i] += 1
				colomn_cnt_white[j] += 1
				picture[i][j] = 0
	i_best = 0
	j_best = 0
	res_best = count_white(i_best, j_best)
	for i in range(n):
		for j in range(m):
			res = count_white(i, j)
			if res < res_best:
				i_best = i
				j_best = j
				res_best = res
	print(res_best)


import sys

def algo(n, m):
	arr = []
	ans = sys.maxsize
	for i in range(n):
		arr.append(list(input()))
	(row, col) = ([0] * n, [0] * m)
	for i in range(n):
		for j in range(m):
			if arr[i][j] == '.':
				(row[i], col[j]) = (row[i] + 1, col[j] + 1)
	for i in range(n):
		for j in range(m):
			alt_ans = row[i] + col[j]
			if arr[i][j] == '.':
				alt_ans -= 1
			ans = min(ans, alt_ans)
	return ans
q = int(input())
for _ in range(q):
	user_input = input()
	(n, m) = user_input.split()
	(n, m) = (int(n), int(m))
	print(algo(n, m))


def main():
	q = int(input())
	while q > 0:
		q -= 1
		line = input().split()
		n = int(line[0])
		m = int(line[1])
		a = [input() for i in range(n)]
		r = [0 for i in range(n)]
		c = [0 for i in range(m)]
		for i in range(n):
			for j in range(m):
				if a[i][j] == '*':
					r[i] += 1
					c[j] += 1
		ans = 1000000000.0
		for i in range(n):
			for j in range(m):
				total = n + m - 1
				painted = r[i] + c[j]
				if a[i][j] == '*':
					painted -= 1
				ans = min(ans, total - painted)
		print(ans)
main()


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	data = []
	(nn, mm) = ([0] * n, [0] * m)
	for j in range(n):
		data.append(input())
		for k in range(m):
			if data[-1][k] == '*':
				nn[j] += 1
				mm[k] += 1
	nnn = max(nn)
	mmm = max(mm)
	fl = 0
	for i in range(n):
		if fl == 1:
			break
		else:
			for j in range(m):
				if nn[i] == nnn and mm[j] == mmm:
					if data[i][j] == '.':
						print(n - nnn + m - mmm - 1)
						fl = 1
						break
	if fl == 0:
		print(n - nnn + m - mmm)


from operator import add

def solve(n, m):
	grid = [[1] * m for _ in range(n)]
	for row in range(n):
		a = input()
		for (i, c) in enumerate(a):
			if c == '*':
				grid[row][i] = 0
	row_sums = [0] * n
	column_sums = [0] * m
	for (i, row) in enumerate(grid):
		row_sums[i] = sum(row)
		column_sums = list(map(add, column_sums, row))
	minimum_row_sum = min(row_sums)
	minimum_rows = []
	for (i, row_sum) in enumerate(row_sums):
		if row_sum == minimum_row_sum:
			minimum_rows.append(i)
	minimum_col_sum = min(column_sums)
	minimum_cols = []
	for (i, col_sum) in enumerate(column_sums):
		if col_sum == minimum_col_sum:
			minimum_cols.append(i)
	if minimum_row_sum + minimum_col_sum == 0:
		print(0)
		return
	bonus = 0
	for minimum_row in minimum_rows:
		if bonus == 1:
			break
		for white_block_index in [index for (index, color) in enumerate(grid[minimum_row]) if color == 1]:
			if white_block_index in minimum_cols:
				bonus = 1
				break
	print(minimum_row_sum + minimum_col_sum - bonus)
q = int(input())
for _ in range(q):
	(n, m) = (int(a) for a in input().split())
	solve(n, m)


from math import *
from collections import *
from itertools import *
from functools import *
from random import *

def getl(t=int):
	return [t(x) for x in input().split()]

def get(t=int):
	return t(input())
alphabet = [chr(x) for x in range(ord('a'), ord('z') + 1)]
alnum = lambda x: ord(x) - ord('a')

def main():
	for i in range(int(input())):
		test()

def getgrid():
	(n, m) = getl()
	grid = []
	for _ in range(n):
		grid += [list(input())]
	return (grid, n, m)

def test():
	(grid, n, m) = getgrid()
	grid_xs = [grid[i].count('*') for i in range(n)]
	grid_ys = [0] * m
	for i in range(n):
		for j in range(m):
			grid_ys[j] += grid[i][j] == '*'
	z = 0
	for i in range(n):
		for j in range(m):
			k = grid_xs[i] + grid_ys[j] + (grid[i][j] == '.')
			z = max(k, z)
	print(n + m - z)
main()


t = int(input())
for i in range(t):
	(n, m) = input().split()
	n = int(n)
	m = int(m)
	lc = [0] * m
	lr = [0] * n
	l = []
	for i in range(0, n):
		s = input()
		l.append(s)
		for j in range(len(s)):
			if s[j] == '.':
				lc[j] += 1
				lr[i] += 1
	min1 = 10 ** 9
	for i in range(0, n):
		for j in range(0, m):
			ans = lr[i] + lc[j]
			if l[i][j] == '.':
				ans = ans - 1
			min1 = min(min1, ans)
	print(min1)


for _ in range(int(input())):
	(n, M) = [int(x) for x in input().split()]
	m = []
	for i in range(n):
		m.append(input())
	cr = [0] * n
	cl = [0] * M
	for i in range(n):
		for j in range(M):
			cr[i] += m[i][j] == '.'
			cl[j] += m[i][j] == '.'
	ans = n * M
	for i in range(n):
		for j in range(M):
			ans = min(ans, cr[i] + cl[j] - (m[i][j] == '.'))
	print(ans)


from sys import stdin
from math import gcd, sqrt
from collections import deque
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
for _ in range(I()):
	ans = 10 ** 12 + 7
	(r, c) = R()
	(r_cnt, c_cnt) = ([0] * r, [0] * c)
	a = []
	for _ in range(r):
		x = S()
		sum = 0
		for i in range(c):
			if x[i] == '.':
				c_cnt[i] += 1
				sum += 1
		r_cnt[_] = sum
		a += (x,)
	for i in range(r):
		for j in range(c):
			ans = min(ans, r_cnt[i] + c_cnt[j] - (1 if a[i][j] == '.' else 0))
	print(ans)


import math
from collections import deque, defaultdict
from sys import stdin, stdout
input = stdin.readline
listin = lambda : list(map(int, input().split()))
mapin = lambda : map(int, input().split())
for _ in range(int(input())):
	(n, m) = mapin()
	dn = defaultdict(int)
	dm = defaultdict(int)
	z = []
	for i in range(n):
		s = input().strip('\n')
		z.append(s)
		for j in range(m):
			if s[j] == '*':
				dm[j] += 1
				dn[i] += 1
	ddn = list(dn.values())
	ddm = list(dm.values())
	dnn = list(dn.keys())
	dmm = list(dm.keys())
	t = 0
	for i in range(len(ddn)):
		for j in range(len(ddm)):
			t = max(t, ddn[i] + ddm[j] - int(z[dnn[i]][dmm[j]] == '*'))
	print(n + m - 1 - t)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	g = [[False] * m for i in range(n)]
	for i in range(n):
		s = input()
		for j in range(m):
			g[i][j] = s[j] == '.'
	cntv = [0] * n
	cnth = [0] * m
	for i in range(n):
		for j in range(m):
			cntv[i] += g[i][j]
			cnth[j] += g[i][j]
	ans = 10 ** 9
	for i in range(n):
		for j in range(m):
			x = cntv[i] + cnth[j]
			if g[i][j]:
				x -= 1
			ans = min(ans, x)
	print(ans)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	A = []
	R = [0] * n
	C = [0] * m
	for i in range(n):
		x = input()
		A.append(x)
		for j in range(m):
			if x[j] == '.':
				R[i] += 1
				C[j] += 1
	min_R = m
	min_C = n
	min_R_A = []
	min_C_A = []
	for i in range(n):
		if R[i] < min_R:
			min_R = R[i]
			min_R_A.clear()
		if R[i] == min_R:
			min_R_A.append(i)
	for i in range(m):
		if C[i] < min_C:
			min_C = C[i]
			min_C_A.clear()
		if C[i] == min_C:
			min_C_A.append(i)
	com = 0
	for i in min_R_A:
		for j in min_C_A:
			if A[i][j] == '.':
				com = 1
				break
	print(min_R + min_C - com)


q = int(input())
for _ in range(q):
	ans = 10000000000
	(n, m) = map(int, input().split())
	picture = []
	dotcount_w = []
	dotcount_h = []
	for _ in range(n):
		picture.append(input())
		dotcount_w.append(picture[-1].count('.'))
	for i in range(m):
		count = 0
		for j in range(n):
			if picture[j][i] == '.':
				count += 1
		dotcount_h.append(count)
	for i in range(m):
		for j in range(n):
			if picture[j][i] == '.':
				ans = min(dotcount_h[i] + dotcount_w[j] - 1, ans)
			else:
				ans = min(dotcount_h[i] + dotcount_w[j], ans)
	print(ans)


t = int(input())
for q in range(t):
	(n, m) = map(int, input().split())
	matrix = [[0] * m for _ in range(n)]
	for i in range(n):
		s = input()
		for j in range(m):
			if s[j] == '.':
				matrix[i][j] = 1
	rsum = [sum(matrix[i]) for i in range(n)]
	csum = [sum((matrix[i][j] for i in range(n))) for j in range(m)]
	ans = min((min((rsum[i] + csum[j] - matrix[i][j] for i in range(n))) for j in range(m)))
	print(ans)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	picture = [None] * n
	for i in range(n):
		picture[i] = input()
	dp = [0]
	rows = [0] * n
	cols = [0] * m
	for i in range(n):
		for j in range(m):
			if picture[i][j] == '.':
				rows[i] += 1
	for i in range(m):
		for j in range(n):
			if picture[j][i] == '.':
				cols[i] += 1
	ans = n * m
	for i in range(n):
		for j in range(m):
			dup = 0 if picture[i][j] == '*' else 1
			ans = min(ans, rows[i] + cols[j] - dup)
	print(ans)


from sys import stdin, stdout
import collections
import math
T = int(input())
for t in range(T):
	(N, M) = [int(x) for x in stdin.readline().split()]
	data = []
	row = [M] * N
	col = [N] * M
	for i in range(N):
		s = input()
		data.append(list(s))
		for j in range(M):
			if s[j] == '*':
				row[i] -= 1
				col[j] -= 1
	min_row = min(row)
	min_col = min(col)
	if min_row == 0 or min_col == 0:
		print(min_row + min_col)
	else:
		r = []
		c = []
		for i in range(N):
			if row[i] == min_row:
				r.append(i)
		for j in range(M):
			if col[j] == min_col:
				c.append(j)
		flag = 0
		for x in r:
			for y in c:
				if data[x][y] == '.' and flag == 0:
					print(min_row + min_col - 1)
					flag = 1
			if flag == 1:
				break
		if flag == 0:
			print(min_row + min_col)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	mt = []
	r = []
	c = []
	for i in range(n):
		mt.append([*input()])
		r.append([[j for j in mt[-1]], i + 1, mt[-1].count('.')])
	for (i, k) in zip([*zip(*mt)], range(1, m + 1)):
		c.append([[j for j in i], k, i.count('.')])
	r.sort(key=lambda x: -x[2])
	c.sort(key=lambda x: -x[2])
	ans = 1000000000.0
	for i in r:
		for j in c:
			t = i[2] + j[2] - int(mt[i[1] - 1][j[1] - 1] == '.')
			ans = min(ans, t)
	print(ans)


for q in range(int(input())):
	set1 = set()
	set2 = set()
	(n, m) = list(map(int, input().split()))
	a = []
	for i in range(n):
		a.append(input())
	min_k1 = 10 ** 18
	for i in range(n):
		k1 = 0
		for j in range(m):
			k1 += a[i][j] == '.'
		if k1 == min_k1:
			set2.add(i)
		if k1 < min_k1:
			min_k1 = k1
			set2 = set()
			set2.add(i)
	min_k2 = 10 ** 18
	for i in range(m):
		k2 = 0
		for j in range(n):
			k2 += a[j][i] == '.'
		if k2 == min_k2:
			set1.add(i)
		if k2 < min_k2:
			min_k2 = k2
			set1 = set()
			set1.add(i)
	for i in range(n):
		for j in range(m):
			if a[i][j] == '.' and i in set2 and (j in set1):
				print(min_k2 + min_k1 - 1)
				break
		else:
			continue
		break
	else:
		print(min_k2 + min_k1)


from sys import stdin

def ii():
	return int(stdin.readline())

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

def li():
	return list(mi())

def si():
	return stdin.readline()
for _ in range(ii()):
	a = []
	r = []
	c = []
	(n, m) = mi()
	for i in range(n):
		a.append(si())
		r.append(a[i].count('.'))
	for j in range(m):
		x = 0
		for i in range(n):
			if a[i][j] == '.':
				x += 1
		c.append(x)
	ans = n + m - 1
	for i in range(n):
		for j in range(m):
			ans = min(ans, r[i] + c[j] - (a[i][j] == '.'))
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	A = []
	for i in range(n):
		B = input()
		A.append(B)
	cnt_n = [0 for i in range(n)]
	cnt_m = [0 for i in range(m)]
	for i in range(n):
		for j in range(m):
			if A[i][j] == '.':
				cnt_n[i] += 1
				cnt_m[j] += 1
	ans = n + m
	for i in range(n):
		for j in range(m):
			if A[i][j] == '.':
				ans = min(ans, cnt_m[j] + cnt_n[i] - 1)
			else:
				ans = min(ans, cnt_n[i] + cnt_m[j])
	print(ans)


num = int(input())
for i in range(num):
	(rows, cols) = map(int, input().split())
	rowsNum = [0] * rows
	colsNum = [0] * cols
	data = []
	for j in range(rows):
		data.append(input())
		for k in range(cols):
			if data[j][k] == '.':
				rowsNum[j] += 1
				colsNum[k] += 1
	minSum = 1 * 10 ** 6
	for i in range(rows):
		for j in range(cols):
			total = rowsNum[i] + colsNum[j]
			if total <= minSum:
				if data[i][j] == '.':
					minSum = total - 1
				else:
					minSum = total
	print(minSum)


import sys
import math
input = sys.stdin.readline
q = int(input())
for i in range(q):
	(n, m) = list(map(int, input().split()))
	r = [0] * n
	c = [0] * m
	arr = []
	for i in range(n):
		arr.append(input())
	for i in range(n):
		for j in range(m):
			if arr[i][j] == '.':
				r[i] += 1
				c[j] += 1
	minn = 1000000000
	for i in range(n):
		for j in range(m):
			if arr[i][j] == '.':
				minn = min(minn, r[i] + c[j] - 1)
			else:
				minn = min(minn, r[i] + c[j])
	print(minn)


qqqq = int(input())
while qqqq > 0:
	(n, m) = map(int, input().split())
	opsonf = [None] * n
	falarr = [0] * 10
	klmn = [0] * n
	falarr[0] = 1
	fhju = [0] * m
	for i in range(n):
		falarr[0] = 1
		opsonf[i] = list(input())
		for j in range(m):
			if opsonf[i][j] == '*':
				falarr[0] = 1
				klmn[i] += 1
				fhju[j] += 1
	ljkjht = n + m - 1
	falarr[0] = 1
	falarr[0] = 1
	for i in range(n):
		for j in range(m):
			falarr[0] = 1
			if opsonf[i][j] == '.':
				falarr[0] = 1
				ljkjht = min(ljkjht, n - klmn[i] + m - fhju[j] - 1)
			else:
				falarr[0] = 1
				ljkjht = min(ljkjht, n - klmn[i] + m - fhju[j])
	falarr[0] = 1
	print(ljkjht)
	qqqq -= 1


N = int(input())
out = []
for i in range(N):
	a = input().split()
	n = int(a[0])
	m = int(a[1])
	arr = []
	n_hor = []
	for j in range(n):
		arr.append(input())
		n_hor.append(arr[-1].count('.'))
	min_hor = min(n_hor)
	i1 = [i for (i, x) in enumerate(n_hor) if x == min_hor]
	n_ver = []
	for j in range(m):
		col = [el[j] for el in arr]
		n_ver.append(col.count('.'))
	min_ver = min(n_ver)
	i2 = [i for (i, x) in enumerate(n_ver) if x == min_ver]
	Flag = False
	for el in i1:
		for ell in i2:
			if arr[el][ell] == '.':
				Flag = True
	if Flag == True:
		out.append(min_hor + min_ver - 1)
	else:
		out.append(min_hor + min_ver)
for el in out:
	print(el)


q = int(input())
for tc in range(q):
	(n, m) = list(map(int, input().split()))
	grid = []
	row = []
	col = []
	for i in range(n):
		row.append(0)
	for i in range(m):
		col.append(0)
	for i in range(n):
		temp = []
		inp = input()
		for j in range(m):
			if inp[j] == '.':
				temp.append(0)
				row[i] = row[i] + 1
				col[j] = col[j] + 1
			else:
				temp.append(1)
		grid.append(temp)
	minVal = float('inf')
	for i in range(n):
		for j in range(m):
			val = 0
			if grid[i][j] == 0:
				val = row[i] + col[j] - 1
			else:
				val = row[i] + col[j]
			if val < minVal:
				minVal = val
	print(minVal)


import sys
n = int(input())
for i in range(0, n):
	ln = [int(j) for j in sys.stdin.readline().rstrip().split(' ')]
	n = ln[0]
	mm = ln[1]
	g = []
	for j in range(0, n):
		g.append(list(sys.stdin.readline().rstrip()))
	s = 0
	mx = 0
	cols = []
	for j in range(0, n):
		m = 0
		for k in range(0, mm):
			if g[j][k] == '*':
				m += 1
		if m > mx:
			cols = [j]
			mx = m
		elif m == mx:
			cols.append(j)
	s += mm - mx
	mx = 0
	cols2 = []
	for j in range(0, mm):
		m = 0
		for k in range(0, n):
			if g[k][j] == '*':
				m += 1
		if m > mx:
			cols2 = [j]
			mx = m
		elif m == mx:
			cols2.append(j)
	s += n - mx
	f = False
	for i in cols:
		for j in cols2:
			if g[i][j] == '.':
				f = True
	if f:
		s -= 1
	print(s)


import sys
import math as mt
import bisect
t = int(input())

def ncr_util():
	inv[0] = inv[1] = 1
	fact[0] = fact[1] = 1
	for i in range(2, 300001):
		inv[i] = inv[i % p] * (p - p // i) % p
	for i in range(1, 300001):
		inv[i] = inv[i - 1] * inv[i] % p
		fact[i] = fact[i - 1] * i % p

def solve():
	dx = [0] * n
	dy = [0] * m
	for i in range(n):
		cnt = 0
		for j in range(m):
			if l[i][j] == '.':
				cnt += 1
		dx[i] = cnt
	for j in range(m):
		cnt = 0
		for i in range(n):
			if l[i][j] == '.':
				cnt += 1
		dy[j] = cnt
	ans = n * m
	for i in range(n):
		for j in range(m):
			if l[i][j] == '.':
				ans = min(dx[i] + dy[j] - 1, ans)
			else:
				ans = min(dx[i] + dy[j], ans)
	return ans
for _ in range(t):
	(n, m) = map(int, input().split())
	l = []
	for i in range(n):
		l.append(input())
	print(solve())


transform = lambda c: 0 if c == '.' else 1
q = int(input())
for _ in range(q):
	(n, m) = map(int, input().strip().split())
	a = []
	for _ in range(n):
		a.append(list(map(transform, list(input().strip()))))
	sum_in_row = [sum(a) for a in a]
	sum_in_col = [sum(a) for a in zip(*a)]
	max_row = max(sum_in_row)
	max_col = max(sum_in_col)
	row_indexes = [i for (i, e) in enumerate(sum_in_row) if e == max_row]
	col_indexes = [i for (i, e) in enumerate(sum_in_col) if e == max_col]
	found = False
	ans = n - max_col + m - max_row
	cross = [a[r][c] for r in row_indexes for c in col_indexes]
	ans -= int(0 in cross)
	print(ans)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for j in range(n):
		a.append(input())
	r = [0] * n
	c = [0] * m
	for j in range(n):
		for k in range(m):
			if a[j][k] == '.':
				r[j] += 1
				c[k] += 1
	an = n * m
	for j in range(n):
		for k in range(m):
			cu = r[j] + c[k]
			if a[j][k] == '.':
				cu -= 1
			an = min(an, cu)
	print(an)


def rint():
	return int(input())

def rints():
	return list(map(int, input().split()))
t = rint()
for _ in range(t):
	(n, m) = rints()
	s = [input() for _ in range(n)]
	rows = [0] * n
	cols = [0] * m
	for (i, si) in enumerate(s):
		for (j, c) in enumerate(si):
			if c == '*':
				rows[i] += 1
				cols[j] += 1
	res = n + m
	for (i, vr) in enumerate(rows):
		for (j, vc) in enumerate(cols):
			res = min(res, n - vc + m - vr - (1 if s[i][j] == '.' else 0))
	print(res)


from math import *
import sys
input = lambda : sys.stdin.readline().strip()
T = int(input())
for _ in range(T):
	(n, m) = map(int, input().split())
	matrix = []
	for i in range(n):
		matrix.append(list(input()))
	row = {}
	column = {}
	for i in range(n):
		row[i] = 0
	for j in range(m):
		column[j] = 0
	for i in range(n):
		for j in range(m):
			if matrix[i][j] == '*':
				row[i] += 1
				column[j] += 1
	Mrow = max(row.values())
	Mcol = max(column.values())
	crows = []
	for (k, v) in row.items():
		if v == Mrow:
			crows.append(k)
	ccols = []
	for (k, v) in column.items():
		if v == Mcol:
			ccols.append(k)
	tot = 0
	for i in crows:
		for j in ccols:
			if matrix[i][j] == '.':
				tot -= 1
				break
		else:
			continue
		break
	tot += n - Mrow + (m - Mcol)
	print(max(0, tot))


def solve(test):
	(n, m) = map(int, input().split())
	sh = [[0 for j in range(m + 1)] for i in range(n + 1)]
	sv = [[0 for j in range(m + 1)] for i in range(n + 1)]
	set_v = [set() for i in range(1, n + 1)]
	set_h = [set() for j in range(1, m + 1)]
	for i in range(1, n + 1):
		row = '0' + input()
		for j in range(1, m + 1):
			if row[j] == '.':
				color = 0
			else:
				color = 1
			sv[i][j] = sv[i][j - 1] + color
			sh[i][j] = sh[i - 1][j] + color
	max_v = max([sv[i][m] for i in range(1, n + 1)])
	max_h = max(sh[n])
	best_columns = []
	for j in range(1, m + 1):
		if sh[n][j] == max_h:
			best_columns.append(j)
	best_rows = []
	for i in range(1, n + 1):
		if sv[i][m] == max_v:
			best_rows.append(i)
	for i in best_rows:
		for j in best_columns:
			if sv[i][j] == sv[i][j - 1]:
				print(m - sv[i][m] + n - sh[n][j] - 1)
				return
	print(m - max_v + n - max_h)
q = int(input())
for test in range(q):
	solve(test)


n = int(input())
for i in range(n):
	(n, m) = [int(x) for x in input().split()]
	inp = list()
	for j in range(n):
		inp.append(input())
	mrow = 0
	mcol = 0
	rowind = list()
	colind = list()
	for j in range(n):
		thisrow = 0
		for k in inp[j]:
			if k == '*':
				thisrow += 1
		if thisrow > mrow:
			rowind.clear()
			rowind.append(j)
			mrow = thisrow
		elif thisrow == mrow:
			rowind.append(j)
	for j in range(m):
		thiscol = 0
		for k in inp:
			if k[j] == '*':
				thiscol += 1
		if thiscol > mcol:
			colind.clear()
			colind.append(j)
			mcol = thiscol
		elif thiscol == mcol:
			colind.append(j)
	i = 0
	j = 0
	found = False
	while i < len(rowind) and (not found):
		while j < len(colind) and (not found):
			if inp[rowind[i]][colind[j]] == '.':
				found = True
			j += 1
		i += 1
		j = 0
	if found:
		print(m + n - mrow - mcol - 1)
	else:
		print(m + n - mrow - mcol)


import sys
import math
from collections import defaultdict, deque
input = sys.stdin.readline

def inar():
	return [int(el) for el in input().split()]

def main():
	t = int(input())
	for _ in range(t):
		(n, m) = inar()
		matrix = []
		for i in range(n):
			matrix.append(list(input().strip()))
		row = [0] * n
		col = [0] * m
		for i in range(n):
			for j in range(m):
				if matrix[i][j] == '.':
					col[j] += 1
					row[i] += 1
		ans = 10 ** 10
		for i in range(n):
			for j in range(m):
				minus = 0
				if matrix[i][j] == '.':
					minus = 1
				ans = min(ans, row[i] + col[j] - minus)
		print(ans)
main()


import io, sys
input = io.StringIO(sys.stdin.buffer.read().decode()).readline
ii = lambda : int(input())
mi = lambda : map(int, input().split())
li = lambda : list(mi())
out = []
for _ in range(ii()):
	(n, m) = mi()
	g = [input() for _ in range(n)]
	free = [row.count('.') for row in g]
	ans = n + m
	for j in range(m):
		hor = m
		ver = 0
		for i in range(n):
			req = free[i]
			if g[i][j] == '.':
				ver += 1
				req -= 1
			hor = min(hor, req)
		ans = min(ans, ver + hor)
	out.append(ans)
print(*out, sep='\n')


from sys import stdin

def get_ints():
	return [int(x) for x in stdin.readline().strip().split()]

def gi():
	return int(input())

def print_ints(ar):
	print(' '.join([str(x) for x in ar]))
for _ in range(gi()):
	(n, m) = get_ints()
	ar = [input() for i in range(n)]
	cntn = [0] * n
	cntm = [0] * m
	for i in range(n):
		for j in range(m):
			cntn[i] += 1 if ar[i][j] == '.' else 0
			cntm[j] += 1 if ar[i][j] == '.' else 0
	ans = n + m
	for i in range(n):
		for j in range(m):
			ans = min(ans, cntn[i] + cntm[j] - (1 if ar[i][j] == '.' else 0))
	print(ans)


from sys import stdin, stdout, exit
q = int(input())
for it in range(q):
	(n, m) = map(int, stdin.readline().split())
	grid = [[0] * m for i in range(n)]
	for i in range(n):
		line = stdin.readline().strip()
		grid[i] = [c for c in line]
	rows = []
	cols = []
	for i in range(n):
		row_ct = 0
		for j in range(m):
			if grid[i][j] == '*':
				row_ct += 1
		rows.append(row_ct)
	for j in range(m):
		col_ct = 0
		for i in range(n):
			if grid[i][j] == '*':
				col_ct += 1
		cols.append(col_ct)
	ans = 0
	for i in range(n):
		for j in range(m):
			this = rows[i] + cols[j] - (1 if grid[i][j] == '*' else 0)
			ans = max(ans, this)
	stdout.write(str(m + n - 1 - ans) + '\n')


from sys import stdin, stdout
from math import floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque
from heapq import merge, heapify, heappop, heappush, nsmallest
from bisect import bisect_left as bl, bisect_right as br, bisect
mod = pow(10, 9) + 7
mod2 = 998244353

def inp():
	return stdin.readline().strip()

def iinp():
	return int(inp())

def out(var, end='\n'):
	stdout.write(str(var) + '\n')

def outa(*var, end='\n'):
	stdout.write(' '.join(map(str, var)) + end)

def lmp():
	return list(mp())

def mp():
	return map(int, inp().split())

def smp():
	return map(str, inp().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(m, val) for j in range(n)]

def remadd(x, y):
	return 1 if x % y else 0

def ceil(a, b):
	return (a + b - 1) // b
S1 = 'abcdefghijklmnopqrstuvwxyz'
S2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'

def isprime(x):
	if x <= 1:
		return False
	if x in (2, 3):
		return True
	if x % 2 == 0:
		return False
	for i in range(3, int(sqrt(x)) + 1, 2):
		if x % i == 0:
			return False
	return True
for _ in range(int(inp())):
	(n, m) = mp()
	ml = []
	r = []
	c = [0 for i in range(m)]
	for i in range(n):
		s = inp()
		r.append(s.count('.'))
		for j in range(m):
			c[j] += s[j] == '.'
		ml.append(s)
	mn = inf
	for i in range(n):
		for j in range(m):
			x = r[i] + c[j]
			if ml[i][j] == '.':
				x -= 1
			mn = min(mn, x)
	print(mn)


for _ in range(int(input(''))):
	(n, m) = map(int, input().split())
	a = []
	nc = [0] * n
	mc = [0] * m
	for i in range(n):
		s = input('')
		a.append(s)
	for i in range(n):
		nc[i] = a[i].count('*')
	for j in range(m):
		for k in range(n):
			if a[k][j] == '*':
				mc[j] += 1
	mmc = max(mc)
	nmc = max(nc)
	if mmc == n and nmc == m:
		print('0')
		continue
	else:
		ans = 10 ** 10
		for j in range(n):
			for k in range(m):
				t = n + m - 1 - (nc[j] + mc[k])
				if a[j][k] == '*':
					t += 1
				ans = min(ans, t)
		print(ans)


for _ in range(int(input())):
	(n, m) = [int(a) for a in input().split()]
	matrix = []
	for i in range(n):
		s = input()
		ar = list(s)
		matrix.append(ar)
	ans = 0
	b = [0] * n
	ar = [0] * m
	for i in range(n):
		for j in range(m):
			if matrix[i][j] == '*':
				b[i] += 1
				ar[j] += 1
	for i in range(n):
		for j in range(m):
			ans = max(ans, ar[j] + b[i] - (matrix[i][j] == '*'))
	print(n + m - 1 - ans)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	(rc, cc) = ([0 for i in range(n)], [0 for i in range(m)])
	mini = 10 ** 10
	s = []
	for i in range(n):
		line = input()
		s.append(line)
		for l in range(m):
			rc[i] += 1 if line[l] == '.' else 0
			cc[l] += 1 if line[l] == '.' else 0
	for i in range(n):
		for j in range(m):
			mini = min(mini, cc[j] + rc[i] - (1 if s[i][j] == '.' else 0))
	print(mini)


from sys import stdin
read = stdin.readline
q = int(read())
for _q in range(q):
	(n, m) = map(int, read().split())
	pic = [read() for i in range(n)]
	c = [0] * m
	r = [0] * n
	for i in range(n):
		for j in range(m):
			if pic[i][j] == '*':
				c[j] += 1
				r[i] += 1
	c = sorted(zip(c, range(m)), reverse=True)
	r = sorted(zip(r, range(n)), reverse=True)
	found = False
	for i in range(n):
		if r[i][0] < r[0][0]:
			break
		for j in range(m):
			if c[j][0] < c[0][0]:
				break
			if pic[r[i][1]][c[j][1]] == '.':
				found = True
	print(n + m - c[0][0] - r[0][0] - found)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	arr = [[0] * m for i in range(n)]
	sum_row = [0] * n
	sum_col = [0] * m
	for i in range(n):
		ip = input()
		add = 0
		for j in range(m):
			if ip[j] == '*':
				arr[i][j] = 1
				add += 1
				sum_col[j] += 1
		sum_row[i] = add
	required_sum = n + m
	minn = required_sum
	for i in range(n):
		for j in range(m):
			if arr[i][j] == 1:
				minn = min(minn, n + m - (sum_row[i] + sum_col[j]))
			else:
				minn = min(minn, n + m - (sum_row[i] + sum_col[j] + 1))
	print(minn)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	field = [['.' for j in range(m)] for g in range(n)]
	for j in range(n):
		string = input()
		for g in range(m):
			field[j][g] = string[g]
	strings = []
	columns = []
	length1 = 0
	length2 = 0
	for j in range(n):
		length3 = 0
		for g in range(m):
			if field[j][g] == '*':
				length3 += 1
		if length3 > length1:
			strings.clear()
			length1 = length3
			strings.append(j)
		elif length3 == length1:
			strings.append(j)
	for j in range(m):
		length3 = 0
		for g in range(n):
			if field[g][j] == '*':
				length3 += 1
		if length3 > length2:
			columns.clear()
			length2 = length3
			columns.append(j)
		elif length3 == length2:
			columns.append(j)
	answer = n - length1 + m - length2
	flag = False
	for string in strings:
		for column in columns:
			if field[string][column] == '.':
				answer -= 1
				flag = True
				break
		if flag:
			break
	print(answer)


from sys import stdin, stdout
u = ''
for _ in ' ' * int(stdin.readline()):
	(a, b) = map(int, stdin.readline().split())
	z = [0] * a
	z1 = [0] * b
	k = []
	for i in range(a):
		x = stdin.readline()
		k += [x]
		for j in range(b):
			if x[j] == '*':
				z1[j] += 1
				z[i] += 1
	ans = 0
	for i in range(a):
		for j in range(b):
			ans = max(ans, z[i] + z1[j] + (k[i][j] == '.'))
	u += str(a + b - ans) + ' '
stdout.write(u)


def get(tab, n, m):
	v = []
	for y in range(n):
		v.append(sum(tab[y]))
	g = [0] * m
	for x in range(m):
		r = 0
		for y in range(n):
			r += tab[y][x]
		g[x] = r
	mn = n + m
	for y in range(n):
		for x in range(m):
			t = g[x] + v[y]
			if tab[y][x] == 1:
				t -= 1
			if t < mn:
				mn = t
	return mn
q = int(input())
for e in range(q):
	(n, m) = map(int, input().split())
	tab = []
	for y in range(n):
		s = input()
		tmp = []
		for x in range(m):
			tmp.append(1 if s[x] == '.' else 0)
		tab.append(tmp)
	print(get(tab, n, m))


t = int(input())
while t != 0:
	t = t - 1
	(n, m) = [int(i) for i in input().split()]
	s = []
	rows = [0] * n
	columns = [0] * m
	for i in range(n):
		b = input()
		s.append(b)
	for i in range(n):
		for j in range(m):
			if s[i][j] == '.':
				rows[i] += 1
				columns[j] += 1
	ans = n + m
	for i in range(n):
		for j in range(m):
			ans = min(ans, rows[i] + columns[j] - (s[i][j] == '.'))
	print(ans)


q = int(input())
for it in range(q):
	flag = 0
	ctr_r = []
	ctr_c = []
	(m, n) = map(int, input().split())
	mapp = [list(input()) for x in range(m)]
	tra = [[mapp[j][i] for j in range(len(mapp))] for i in range(len(mapp[0]))]
	max_r = mapp[0].count('*')
	max_c = tra[0].count('*')
	for k in range(m):
		z = mapp[k].count('*')
		if z > max_r:
			ctr_r = [k]
			max_r = z
		elif z == max_r:
			ctr_r.append(k)
	for k in range(n):
		z = tra[k].count('*')
		if z > max_c:
			ctr_c = [k]
			max_c = z
		elif z == max_c:
			ctr_c.append(k)
	for i in ctr_r:
		for j in ctr_c:
			if mapp[i][j] != '*':
				flag = 1
	ans = m - max_r + (n - max_c) - flag
	print(ans)


def solve(grid, n, m):
	dp = [[[0 for k in range(2)] for i in range(m)] for j in range(n)]
	for i in range(n):
		count = 0
		for j in range(m):
			if grid[i][j] == '*':
				count += 1
		for j in range(m):
			dp[i][j][0] = count
	for j in range(m):
		count = 0
		for i in range(n):
			if grid[i][j] == '*':
				count += 1
		for i in range(n):
			dp[i][j][1] = count
	min_val = float('inf')
	for i in range(n):
		for j in range(m):
			diff = n + m - dp[i][j][0] - dp[i][j][1]
			if grid[i][j] == '.':
				diff -= 1
			min_val = min(min_val, diff)
	print(min_val)

def main():
	t = int(input())
	for i in range(t):
		(n, m) = map(int, input().split())
		grid = []
		for j in range(n):
			grid.append(list(input()))
		solve(grid, n, m)
main()


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	l1 = []
	l2 = []
	l = []
	INF = 99 ** 9
	for i in range(n):
		t = list(input())
		l.append(t)
		l1.append(t.count('.'))
	for i in range(m):
		l2.append(0)
		for a in range(n):
			t = l[a][i]
			if t == '.':
				l2[-1] += 1
	best = INF
	for i in range(n):
		for a in range(m):
			if l[i][a] == '.':
				r = 0
				r += l2[a]
				r += l1[i]
				r -= 1
			else:
				r = 0
				r += l2[a]
				r += l1[i]
			best = min(r, best)
	print(best)


q = int(input())
import collections
for qq in range(q):
	(h, w) = map(int, input().split())
	dat = []
	dat_count = []
	for hh in range(h):
		l = input()
		dat.append(l)
		c = collections.Counter(l)
		dat_count.append([c['.']] * w)
	for ww in range(w):
		c = 0
		for hh in range(h):
			if dat[hh][ww] == '.':
				c += 1
		if c == 0:
			continue
		for hh in range(h):
			if dat[hh][ww] == '.':
				dat_count[hh][ww] += c - 1
			else:
				dat_count[hh][ww] += c
	res = 10000000000000
	for i in range(len(dat_count)):
		res = min(res, min(dat_count[i]))
	print(res)


q = int(input())
for t in range(q):
	(n, m) = map(int, input().split())
	s = (n + 1) * ['']
	flag = False
	d = [(m + 1) * [0] for t in range(n + 1)]
	stat = [(m + 1) * [False] for t in range(n + 1)]
	d1 = [(m + 1) * [0] for t in range(n + 1)]
	for i in range(1, n + 1):
		s[i] = '.' + input()
		for j in range(1, m + 1):
			if s[i][j] == '*':
				stat[i][j] = True
				d[i][j] += d[i][j - 1] + 1
				d1[i][j] += d1[i - 1][j] + 1
			else:
				d[i][j] += d[i][j - 1]
				d1[i][j] += d1[i - 1][j]
	max_ = 10 ** 20
	for i in range(1, m + 1):
		for j in range(1, n + 1):
			if stat[j][i]:
				max_ = min(max_, n + m - d1[-1][i] - d[j][-1])
			else:
				max_ = min(max_, n + m - d1[-1][i] - d[j][-1] - 1)
	print(max_)


import sys
for _ in range(int(input())):
	(n, m) = map(int, input().split())
	row = 0
	col = [0 for _ in range(m)]
	board = []
	problemRow = []
	problemCol = []
	c = 0
	need = 0
	mn = m + n
	for i in range(n):
		next = sys.stdin.readline()
		board.append(next)
		problemRow.append(next.count('.'))
	for i in range(m):
		cur = 0
		for j in range(n):
			if board[j][i] == '.':
				cur += 1
		problemCol.append(cur)
	for i in range(n):
		for j in range(m):
			total = problemRow[i] + problemCol[j]
			if board[i][j] == '.':
				mn = min(mn, total - 1)
			else:
				mn = min(mn, total)
	print(mn)


q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	a = []
	for i in range(n):
		a.append(input())
	h = [i.count('.') for i in a]
	v = []
	for j in range(m):
		v.append(0)
		for i in range(n):
			if a[i][j] == '.':
				v[-1] += 1
	ans = n * m
	for i in range(n):
		for j in range(m):
			ans = min(ans, h[i] + v[j] - (1 if a[i][j] == '.' else 0))
	print(ans)


for i in range(int(input())):
	(n, m) = map(int, input().split())
	a = []
	for j in range(n):
		a.append(input())
	h = []
	for j in a:
		h.append(j.count('.'))
	v = []
	for j in range(m):
		v.append(0)
		for k in range(n):
			if a[k][j] == '.':
				v[-1] += 1
	res = n * m
	for i in range(n):
		for j in range(m):
			res = min(res, h[i] + v[j] - (1 if a[i][j] == '.' else 0))
	print(res)


import sys
q = int(input())
for _ in range(q):
	(n, m) = map(int, input().split())
	countr = []
	countc = []
	a = []
	for i in range(n):
		a.append(input())
		count = 0
		for x in a[i]:
			if x == '.':
				count += 1
		countr.append(count)
	for j in range(m):
		count = 0
		for i in range(n):
			if a[i][j] == '.':
				count += 1
		countc.append(count)
	ans = sys.maxsize
	for i in range(n):
		for j in range(m):
			temp = countr[i] + countc[j]
			if a[i][j] == '.':
				temp -= 1
			ans = min(ans, temp)
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split(' '))
	a = [0] * n
	for i in range(n):
		a[i] = list(input())
	maxrow = 0
	r = []
	for i in range(n):
		val = 0
		for j in range(m):
			if a[i][j] == '*':
				val += 1
		if val > maxrow:
			maxrow = val
			r = []
		if val == maxrow:
			r.append(i)
	maxcol = 0
	c = []
	for j in range(m):
		val = 0
		for i in range(n):
			if a[i][j] == '*':
				val += 1
		if val > maxcol:
			maxcol = val
			c = []
		if val == maxcol:
			c.append(j)
	ans = n - maxrow + m - maxcol
	flag = 0
	for row in r:
		for col in c:
			if a[row][col] == '.':
				ans -= 1
				flag = 1
				break
		if flag == 1:
			break
	print(ans)


q = int(input())
while q > 0:
	q -= 1
	(n, m) = map(int, input().split())
	a = []
	u = [[0] * (m + 1) for i in range(n + 1)]
	l = [[0] * (m + 1) for i in range(n + 1)]
	for i in range(n):
		a.append(input())
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			u[i][j] = u[i - 1][j]
			l[i][j] = l[i][j - 1]
			if a[i - 1][j - 1] == '.':
				u[i][j] += 1
				l[i][j] += 1
	ans = 400006
	for i in range(1, n + 1):
		for j in range(1, m + 1):
			d = 0
			if a[i - 1][j - 1] == '.':
				d = 1
			ans = min(u[n][j] + l[i][m] - d, ans)
	print(ans)


t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	(a, row, col) = ([], [0] * n, [0] * m)
	for i in range(n):
		a.append(list(input()))
	for x in range(n):
		for y in range(m):
			if a[x][y] == '.':
				row[x] += 1
				col[y] += 1
	ans = n + m
	for x in range(n):
		for y in range(m):
			d = row[x] + col[y]
			if a[x][y] == '.':
				d -= 1
			ans = min(ans, d)
	print(ans)


from bisect import *
from collections import *
from itertools import *
import functools
import sys
import math
from decimal import *
from copy import *
getcontext().prec = 30
MAX = sys.maxsize
MAXN = 10 ** 5 + 10
MOD = 10 ** 9 + 7

def isprime(n):
	n = abs(int(n))
	if n < 2:
		return False
	if n == 2:
		return True
	if not n & 1:
		return False
	for x in range(3, int(n ** 0.5) + 1, 2):
		if n % x == 0:
			return False
	return True

def mhd(a, b):
	return abs(a[0] - b[0]) + abs(b[1] - a[1])

def charIN(x=' '):
	return sys.stdin.readline().strip().split(x)

def arrIN(x=' '):
	return list(map(int, sys.stdin.readline().strip().split(x)))

def eld(x, y):
	a = y[0] - x[0]
	b = x[1] - y[1]
	return (a * a + b * b) ** 0.5

def lgcd(a):
	g = a[0]
	for i in range(1, len(a)):
		g = math.gcd(g, a[i])
	return g

def ms(a):
	msf = -MAX
	meh = 0
	st = en = be = 0
	for i in range(len(a)):
		meh += a[i]
		if msf < meh:
			msf = meh
			st = be
			en = i
		if meh < 0:
			meh = 0
			be = i + 1
	return (msf, st, en)

def ncr(n, r):
	num = den = 1
	for i in range(r):
		num = num * (n - i) % MOD
		den = den * (i + 1) % MOD
	return num * pow(den, MOD - 2, MOD) % MOD

def flush():
	return sys.stdout.flush()
for _ in range(int(input())):
	(n, m) = arrIN()
	a = []
	for i in range(n):
		a.append([i for i in input()])
	r = [0] * n
	c = [0] * m
	for i in range(n):
		for j in range(m):
			if a[i][j] == '*':
				r[i] += 1
				c[j] += 1
	mxc = max(c)
	ans = MAX
	for i in range(m):
		if c[i] == mxc:
			mn = 0
			tempr = [k for k in r]
			for j in range(n):
				if a[j][i] == '.':
					tempr[j] += 1
					mn += 1
			mn += m - max(tempr)
			ans = min(ans, mn)
	print(ans)


q = int(input())
for _ in range(q):
	(a, r, c) = ([], [], [])
	(n, m) = map(int, input().split())
	for _ in range(n):
		a.append(input())
	for i in range(n):
		r.append(0)
		for j in range(m):
			if a[i][j] == '.':
				r[i] += 1
	for j in range(m):
		c.append(0)
		for i in range(n):
			if a[i][j] == '.':
				c[j] += 1
	res = n + m
	for i in range(n):
		for j in range(m):
			if a[i][j] == '.':
				res = min(r[i] + c[j] - 1, res)
			else:
				res = min(r[i] + c[j], res)
	print(res)


q = int(input())
for i in range(q):
	(n, m) = map(int, input().split())
	rows_map = [[0 for _ in range(m)] for _ in range(n)]
	cols = [m] * m
	rows = [n] * n
	for j in range(n):
		for (i, c) in enumerate(input()):
			if c == '*':
				cols[i] -= 1
				rows[j] -= 1
			else:
				rows_map[j][i] = -1
	ans = n + m
	for (i, r) in enumerate(rows):
		for (j, c) in enumerate(cols):
			ans = min(ans, r + c + rows_map[i][j])
	print(ans)


for _ in range(int(input())):
	(n, m) = map(int, input().split())
	grid = [list(input()) for _ in range(n)]
	rot = list(zip(*grid))
	rows = [grid[i].count('.') for i in range(n)]
	cols = [rot[i].count('.') for i in range(m)]
	ans = 2147483647
	for y in range(n):
		for x in range(m):
			tmp = rows[y] + cols[x] - (1 if grid[y][x] == '.' else 0)
			ans = min(ans, tmp)
	print(ans)