#include <bits/stdc++.h>
using namespace std;
const int MAXN = 400010, INF = 1e9;
int n, m, q;
int s[MAXN], h[MAXN], l[MAXN];
int main() {
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    scanf("%d%d", &n, &m);
    for (int i = 0; i < n; ++i) h[i] = 0;
    for (int j = 0; j < m; ++j) l[j] = 0;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) s[i * m + j] = 0;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) {
        char c;
        cin >> c;
        if (c == '.')
          s[i * m + j] = 0;
        else
          s[i * m + j] = 1;
        h[i] += s[i * m + j];
        l[j] += s[i * m + j];
      }
    int ans = INF;
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < m; ++j) {
        ans = min(ans, (n + m - 1) - (h[i] + l[j] - s[i * m + j]));
      }
    printf("%d\n", ans);
  }
  return 0;
}
