#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int mod = 998244353;
const int INF = 1e9;
string G[50000];
int r[50000], c[50000];
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0);
  int q;
  cin >> q;
  while (q--) {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) cin >> G[i];
    for (int i = 0; i < n; i++) {
      r[i] = 0;
      for (int j = 0; j < m; j++)
        if (G[i][j] == '.') r[i]++;
    }
    for (int j = 0; j < m; j++) {
      c[j] = 0;
      for (int i = 0; i < n; i++)
        if (G[i][j] == '.') c[j]++;
    }
    int ans = n + m - 1;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++)
        ans = min(ans, r[i] + c[j] - (G[i][j] == '.'));
    }
    printf("%d\n", ans);
  }
  return 0;
}
