------
## 最终结论
```python
import sys

input = sys.stdin.read
data = input().splitlines()

index = 0
q = int(data[index])
index += 1

results = []

for _ in range(q):
    n, m = map(int, data[index].split())
    index += 1
    grid = [data[index + i] for i in range(n)]
    index += n
    
    row_white_count = [0] * n
    col_white_count = [0] * m
    
    # Count white cells in each row and column
    for i in range(n):
        for j in range(m):
            if grid[i][j] == '.':
                row_white_count[i] += 1
                col_white_count[j] += 1
    
    min_paint = float('inf')
    
    # Find the minimum paint needed to create a cross
    for i in range(n):
        for j in range(m):
            # Calculate the number of white cells needed to paint
            needed_paint = row_white_count[i] + col_white_count[j]
            if grid[i][j] == '.':
                needed_paint -= 1
            
            min_paint = min(min_paint, needed_paint)
    
    results.append(min_paint)

print('\n'.join(map(str, results)))
```