#include <bits/stdc++.h>
using namespace std;
int q, n, m;
pair<int, int> row[50001], col[50001];
set<int> row_white[50001];
char c;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> q;
  for (int st = 1; st <= q; st++) {
    cin >> n >> m;
    for (int i = 1; i <= n; i++) row[i] = {0, i};
    for (int i = 1; i <= m; i++) col[i] = {0, i};
    for (int i = 1; i <= n; i++) {
      row_white[i].clear();
      for (int j = 1; j <= m; j++) {
        cin >> c;
        if (c == '*') {
          row[i].first++;
          col[j].first++;
        } else
          row_white[i].insert(j);
      }
    }
    sort(row + 1, row + n + 1);
    sort(col + 1, col + m + 1);
    int ans = m - row[n].first + n - col[m].first;
    if (row[n].first == m || col[m].first == n) {
      cout << ans << endl;
      continue;
    }
    bool found = false;
    for (int i = n; i >= 1; i--) {
      if (row[i].first != row[n].first) break;
      for (int j = m; j >= 1; j--) {
        if (col[j].first != col[m].first) break;
        if (row_white[row[i].second].find(col[j].second) !=
            row_white[row[i].second].end()) {
          ans--;
          found = true;
          break;
        }
      }
      if (found) break;
    }
    cout << ans << endl;
  }
}
