#include <bits/stdc++.h>
using namespace std;
long long int power(long long int x, long long int y, long long int p) {
  long long int res = 1;
  x = x % p;
  while (y > 0) {
    if (y & 1) res = (res * x) % p;
    y = y >> 1;
    x = (x * x) % p;
  }
  return res;
}
long long int modInverse(long long int A, long long int M) {
  return power(A, M - 2, M);
}
int phi(int n) {
  float result = n;
  for (int p = 2; p * p <= n; ++p) {
    if (n % p == 0) {
      while (n % p == 0) n /= p;
      result *= (1.0 - (1.0 / (float)p));
    }
  }
  if (n > 1) result *= (1.0 - (1.0 / (float)n));
  return (int)result;
}
void openFiles() {
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
}
void swap(int* a, int* b) {
  int t = *a;
  *a = *b;
  *b = t;
}
int prime_factor[100000];
vector<pair<int, int> > prime_factors[100000];
void GeneratePrimeFactors(int N) {
  for (int i = 2; i < N; i++) {
    if (prime_factor[i] != 0) continue;
    prime_factor[i] = i;
    for (int j = 2 * i; j < N; j += i) {
      prime_factor[j] = i;
    }
  }
  for (int i = 2; i < N; i++) {
    int x = i;
    map<int, int> M;
    while (x != 1) {
      M[prime_factor[x]]++;
      x /= prime_factor[x];
    }
    for (auto v : M) {
      prime_factors[i].push_back(v);
    }
  }
}
bool prime[1000007];
void Seive(int N) {
  memset(prime, true, sizeof(prime));
  for (int i = 2; i <= N; i++) {
    if (prime[i]) {
      for (int j = 2 * i; j <= N; j += i) prime[j] = false;
    }
  }
}
void multiply(long long int a[2][2], long long int b[2][2]) {
  long long int mul[2][2];
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      mul[i][j] = 0;
      for (int k = 0; k < 2; k++) {
        mul[i][j] =
            (mul[i][j] + (a[i][k] % 1000000007 * b[k][j] % 1000000007)) %
            1000000007;
      }
    }
  }
  for (int i = 0; i < 2; i++) {
    for (int j = 0; j < 2; j++) {
      a[i][j] = mul[i][j] % 1000000007;
    }
  }
}
void power(long long int M[2][2], long long int n) {
  if (n == 0 || n == 1) return;
  long long int M1[2][2] = {{1, 1}, {1, 0}};
  power(M, n / 2);
  multiply(M, M);
  if (n % 2 != 0) multiply(M, M1);
}
long long int fib(long long int n) {
  long long int M[2][2] = {{1, 1}, {1, 0}};
  if (n == 0) return 0;
  power(M, n - 1);
  return M[0][0] % 1000000007;
}
vector<int> parent, v_rank;
void make_set(int v) {
  parent[v] = v;
  v_rank[v] = 0;
}
int find_set(int v) {
  if (v == parent[v]) return v;
  return parent[v] = find_set(parent[v]);
}
void union_sets(int a, int b) {
  a = find_set(a);
  b = find_set(b);
  if (a != b) {
    if (v_rank[a] < v_rank[b]) swap(a, b);
    parent[b] = a;
    if (v_rank[a] == v_rank[b]) v_rank[a]++;
  }
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  int t;
  cin >> t;
  while (t--) {
    int n, m;
    cin >> n >> m;
    map<int, int> r, c;
    for (int i = 0; i < n; i++) r[i] = 0;
    for (int j = 0; j < m; j++) c[j] = 0;
    char a[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        cin >> a[i][j];
        if (a[i][j] == '.') {
          r[i]++;
          c[j]++;
        }
      }
    }
    int mn1 = INT_MAX, mn2 = INT_MAX;
    for (int i = 0; i < n; i++) {
      if (mn1 > r[i]) {
        mn1 = r[i];
      }
    }
    for (int j = 0; j < m; j++) {
      if (mn2 > c[j]) {
        mn2 = c[j];
      }
    }
    set<int> row, col;
    for (int i = 0; i < n; i++) {
      if (r[i] == mn1) {
        row.insert(i);
      }
    }
    for (int j = 0; j < m; j++) {
      if (c[j] == mn2) {
        col.insert(j);
      }
    }
    int ans = INT_MAX;
    for (auto x : row) {
      for (auto y : col) {
        if (a[x][y] == '.') {
          ans = min(ans, r[x] + c[y] - 1);
        } else {
          ans = min(ans, r[x] + c[y]);
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}
