#include <bits/stdc++.h>
using namespace std;
string str[400005];
int cr[400005], cc[400005];
int main() {
  int i, j, k;
  int t, r, c;
  cin >> t;
  while (t--) {
    cin >> r >> c;
    for (i = 0; i < r; ++i) cin >> str[i];
    for (i = 0; i < r; ++i) {
      cr[i] = 0;
      for (j = 0; j < c; ++j) cr[i] += (str[i][j] == '.');
    }
    for (j = 0; j < c; ++j) {
      cc[j] = 0;
      for (i = 0; i < r; ++i) cc[j] += (str[i][j] == '.');
    }
    int mn = 1e9;
    for (i = 0; i < r; ++i) {
      for (j = 0; j < c; ++j) {
        k = cr[i] + cc[j] - (str[i][j] == '.');
        mn = min(mn, k);
      }
    }
    cout << mn << endl;
  }
}
