#include <bits/stdc++.h>
using namespace std;
int main() {
  int q;
  cin >> q;
  while (q--) {
    int n, m;
    cin >> n >> m;
    int a[n][m];
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        char ch;
        cin >> ch;
        if (ch == '.')
          a[i][j] = 0;
        else
          a[i][j] = 1;
      }
    }
    pair<int, int> x[n], y[m];
    for (int i = 0; i < n; i++) {
      int c = 0;
      for (int j = 0; j < m; j++) {
        if (a[i][j] == 1) c++;
      }
      x[i].first = c;
      x[i].second = i;
    }
    for (int i = 0; i < m; i++) {
      int c = 0;
      for (int j = 0; j < n; j++) {
        if (a[j][i] == 1) {
          c++;
        }
      }
      y[i].first = c;
      y[i].second = i;
    }
    sort(x, x + n);
    sort(y, y + m);
    int ans = m - y[m - 1].first + n - x[n - 1].first;
    if (ans == 0) {
      cout << ans << endl;
      continue;
    }
    for (int i = n - 1; i >= 0; i--) {
      if (x[i].first == x[n - 1].first) {
        for (int j = m - 1; j >= 0; j--) {
          if (y[j].first == y[m - 1].first) {
            if (a[x[i].second][y[j].second] == 0) {
              ans--;
              goto p;
            }
          } else {
            break;
          }
        }
      } else
        break;
    }
  p:
    cout << ans << endl;
  }
}
