#include <bits/stdc++.h>
using namespace std;
string g[50001];
long long cnt[50001];
int main() {
  long long q;
  cin >> q;
  while (q--) {
    long long n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
      cin >> g[i];
      g[i] = '@' + g[i];
    }
    memset(cnt, 0, sizeof(cnt));
    for (int i = 1; i <= n; i++) {
      for (int j = 1; j <= m; j++) {
        if (g[i][j] == '.') {
          cnt[i]++;
        }
      }
    }
    long long min_s = 0x3f3f3f3f;
    for (int i = 1; i <= m; i++) {
      long long cn = 0;
      for (int j = 1; j <= n; j++) {
        if (g[j][i] == '.') {
          cn++;
        }
      }
      for (int k = 1; k <= n; k++) {
        if (g[k][i] == '.') {
          min_s = min(min_s, cn + cnt[k] - 1);
        } else
          min_s = min(min_s, cn + cnt[k]);
      }
    }
    cout << min_s << endl;
  }
  return 0;
}
