#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t > 0) {
    --t;
    int n, m;
    cin >> n >> m;
    vector<vector<int>> vec(n, vector<int>(m));
    for (int i = 0; i < n; ++i) {
      for (int j = 0; j < m; ++j) {
        char c;
        cin >> c;
        if (c == '.') {
          vec[i][j] = 0;
        } else
          vec[i][j] = 1;
      }
    }
    int mw = 0, mh = 0;
    int num_w = 0, num_h = 0;
    vector<int> heights, widths;
    for (int i = 0; i < n; ++i) {
      int w = 0;
      for (int j = 0; j < m; ++j) {
        if (vec[i][j] == 1) {
          ++w;
        }
      }
      if (w > mw) {
        widths.clear();
        widths.push_back(i);
      } else if (w == mw) {
        widths.push_back(i);
      }
      mw = max(mw, w);
    }
    for (int i = 0; i < m; ++i) {
      int h = 0;
      for (int j = 0; j < n; ++j) {
        if (vec[j][i] == 1) {
          ++h;
        }
      }
      if (h > mh) {
        heights.clear();
        heights.push_back(i);
      } else if (h == mh) {
        heights.push_back(i);
      }
      mh = max(mh, h);
    }
    if (mh == n && mw == m) {
      cout << 0 << endl;
    } else if (mh == n && mw < m) {
      cout << m - mw << endl;
    } else if (mh < n && mw == m) {
      cout << n - mh << endl;
    } else if (mh < n && mw < m) {
      bool f = false;
      for (auto hi : heights) {
        for (auto wi : widths) {
          if (vec[wi][hi] == 0) {
            f = true;
          }
        }
      }
      if (f) {
        cout << (n + m) - (mh + mw + 1) << endl;
      } else
        cout << (n + m) - (mh + mw) << endl;
    }
  }
  return 0;
}
