#include <bits/stdc++.h>
using ll = long long;
using namespace std;
template <typename... Args>
void read(Args &...args) {
  ((cin >> args), ...);
}
template <typename... Args>
void write(Args... args) {
  ((cout << args << " "), ...);
}
template <typename... Args>
void writeln(Args... args) {
  ((cout << args << " "), ...);
  cout << "\n";
}
template <typename T>
void read(vector<T> &a) {
  for (auto &ele : a) cin >> ele;
}
template <typename T>
void writeln(vector<T> &a) {
  for (auto &ele : a) cout << ele << ' ';
  cout << "\n";
}
const pair<int, int> dxy[] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
const pair<int, int> fxy[] = {{-1, 0}, {1, 0},   {0, -1}, {0, 1},
                              {1, 1},  {-1, -1}, {-1, 1}, {1, -1}};
void solve() {
  int n, m;
  read(n, m);
  char a[n][m];
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      read(a[i][j]);
    }
  }
  vector<int> row(n), col(m);
  int res = 0x3f3f3f3f;
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < m; ++j) {
      if (a[i][j] == '.') {
        row[i]++;
      }
    }
  }
  for (int j = 0; j < m; ++j) {
    for (int i = 0; i < n; ++i) {
      if (a[i][j] == '.') {
        col[j]++;
      }
    }
    for (int i = 0; i < n; ++i) {
      int tmp = row[i] + col[j];
      if (a[i][j] == '.') {
        tmp--;
      }
      res = min(res, tmp);
    }
  }
  writeln(res);
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios::sync_with_stdio(false);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
