#include <bits/stdc++.h>
using namespace std;
const int maxn = 4e5 + 10;
const int maxm = 5e4 + 10;
char G[maxn], s[maxm];
int row[maxm], cal[maxm], n, m;
map<int, int> r, c;
int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    scanf("%d%d", &n, &m);
    memset(row, 0, sizeof(row));
    memset(cal, 0, sizeof(cal));
    for (int i = 0; i < n; i++) {
      scanf("%s", s);
      for (int j = 0; j < m; j++) {
        if (s[j] == '*') {
          row[i]++;
          cal[j]++;
        }
        G[i * m + j] = s[j];
      }
    }
    int mr = 0, mc = 0;
    for (int i = 0; i < n; i++) mr = max(row[i], mr);
    for (int i = 0; i < m; i++) mc = max(cal[i], mc);
    r.clear();
    c.clear();
    for (int i = 0; i < n; i++) {
      if (row[i] == mr) r[i]++;
    }
    for (int i = 0; i < m; i++) {
      if (cal[i] == mc) c[i]++;
    }
    int ans = n + m - mr - mc;
    if (ans != 0) {
      bool flag = false;
      map<int, int>::iterator it = r.begin();
      for (; it != r.end(); it++) {
        int k = it->first;
        for (int i = 0; i < m; i++) {
          if (G[k * m + i] == '.' && c[i] > 0) {
            ans--;
            flag = true;
            break;
          }
        }
        if (flag) break;
      }
    }
    printf("%d\n", ans);
  }
}
