#include <bits/stdc++.h>
const double PI = 3.141592653589793238460;
const long long int MOD = 1000000007;
using namespace std;
bool cmp(const pair<int, int> &a, const pair<int, int> &b) {
  return (a.second < b.second);
}
int main() {
  int t;
  scanf("%d", &t);
  for (int q = 1; q <= t; q++) {
    int n, m, s1 = 0, s2 = 0, res;
    cin >> n >> m;
    char ch;
    vector<int> r, c;
    vector<vector<int> > v(n, vector<int>(m));
    for (int i = int(0); i <= int(n - 1); i++) {
      s1 = 0;
      for (int j = int(0); j <= int(m - 1); j++) {
        cin >> ch;
        if (ch == '.')
          v[i][j] = 0;
        else
          v[i][j] = 1, s1++;
      }
      r.push_back(s1);
    }
    for (int i = int(0); i <= int(m - 1); i++) {
      s2 = 0;
      for (int j = int(0); j <= int(n - 1); j++) s2 += v[j][i];
      c.push_back(s2);
    }
    int mx = 1e9;
    for (int i = int(0); i <= int(n - 1); i++) {
      int row = n - r[i];
      for (int j = int(0); j <= int(m - 1); j++) {
        res = row + (m - c[j]);
        if (v[i][j] == 0) res--;
        mx = min(mx, res);
      }
    }
    cout << mx << endl;
  }
  return 0;
}
