#include <bits/stdc++.h>
using namespace std;
const char nl = '\n';
const int INF = 0x3f3f3f3f;
const long long INFLL = 0x3f3f3f3f3f3f3f3f;
const long long MOD = 1e9 + 7;
const long double EPS = 1e-10;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
const int N = 5e4 + 1;
string grid[N];
int row[N], col[N];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int T;
  cin >> T;
  while (T--) {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n; i++) {
      cin >> grid[i];
      row[i] = 0;
      for (int j = 0; j < m; j++) {
        row[i] += (grid[i][j] == '.');
      }
    }
    for (int j = 0; j < m; j++) {
      col[j] = 0;
      for (int i = 0; i < n; i++) {
        col[j] += (grid[i][j] == '.');
      }
    }
    int ans = INF;
    for (int i = 0; i < n; i++) {
      for (int j = 0; j < m; j++) {
        ans = min(ans, row[i] + col[j] - (grid[i][j] == '.'));
      }
    }
    cout << ans << nl;
  }
  return 0;
}
