#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair

const int N=1e7+10;
const long long INF=1e18;
const double eps=0.0000001;
const ll mod=1e9+7;
int n,m,x,y,t;

struct note
{
    int x,id;
}a[N],b[N];

bool cmp(note a,note b)
{
    return a.x<b.x;
}
string str;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       cin>>n>>m;
       int vis[n][m]={0};
       for(int i=0;i<n;i++)
       {
           cin>>str;
           for(int j=0;j<m;j++)
           {
               if(str[j]=='*')
                a[j].x++,a[j].id=j,b[i].x++,b[i].id=i;
               if(str[j]=='.')
                vis[i][j]=1;
           }
       }
       sort(a,a+m,cmp);
       sort(b,b+n,cmp);
       int flag=0;
       for(int i=n-1;i>=0;i--)
       {
           if(b[i].x==b[n-1].x)
           {
               for(int j=m-1;j>=0;j--)
               {
                   if(a[j].x==a[m-1].x)
                   {
                       if(vis[b[i].id][a[j].id]==1)
                       {
                           cout<<"                       "<<b[i].id<<" "<<a[j].id<<endl;
                           flag=1;
                           //cout<<i<<" "<<j;
                           break;
                       }
                   }
                   else
                    break;
               }
           }
           else break;
       }
        if(flag==0)
            cout<<n+m-(a[m-1].x+b[n-1].x)<<endl;
        else
            cout<<n+m-(a[m-1].x+b[n-1].x)-1<<endl;
    }
}

/*
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<stack>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

const int maxn=1e5+7;
int st[maxn][20],st1[maxn][20],a[maxn],n;

void init(int n)
{
    for(int i=1;i<=n;i++)  st1[i][0]=st[i][0]=a[i];//��ʼ������i�㿪ʼ2^j���ȵļ�ֵ
    for(int j=1;j<20;j++)
        for(int i=1;i<=n;i++)
            if(i+(1<<(j-1))<n)
                st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]),
                st1[i][j]=max(st1[i][j-1],st1[i+(1<<(j-1))][j-1]); //��ֵ
}

int query(int l,int r)
{
    int len=log2(r-l+1);
    return max(st1[l][len],st1[r-(1<<len)+1][len])-min(st[l][len],st[r-(1<<len)+1][len]);
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);\
   int n,s,len; cin>>n>>>s>>len;

    for(int i=1;i<=n;i++) cin>>a[i];
    init(n);
    int l,r;
    if(len>n||query(1,len)>s) return cout<<-1<<endl,0;
    memset(dp,inf,sizeof(dp)); dp[0]=0;

}
*/


#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair

const int N=5e4+10;
const long long INF=1e18;
const double eps=0.0000001;
const ll mod=1e9+7;
int n,m,x,y,t;

struct note
{
    int x,id;
}a[N],b[N];

bool cmp(note a,note b)
{
    return a.x<b.x;
}
string str;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       cin>>n>>m;
       int vis[n][m]={0};
       for(int i=0;i<n;i++)
       {
           cin>>str;
           for(int j=0;j<m;j++)
           {
               if(str[j]=='*')
                a[j].x++,a[j].id=j,b[i].x++,b[i].id=i;
               if(str[j]=='.')
                vis[i][j]=1;
           }
       }
       sort(a,a+m,cmp);
       sort(b,b+n,cmp);
       int flag=0;
       for(int i=n-1;i>=0;i--)
       {
           if(b[i].x==b[n-1].x)
           {
               for(int j=m-1;j>=0;j--)
               {
                   if(a[j].x==a[m-1].x)
                   {
                       if(vis[b[i].id][a[j].id]==1)
                       {

                           flag=1;
                           //cout<<i<<" "<<j;
                           break;
                       }
                   }
                   else
                    break;
               }
           }
           else break;
       }
        if(flag==0)
            cout<<n+m-(a[m-1].x+b[n-1].x)<<endl;
        else
            cout<<n+m-(a[m-1].x+b[n-1].x)-1<<endl;
    }
}

/*
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<stack>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

const int maxn=1e5+7;
int st[maxn][20],st1[maxn][20],a[maxn],n;

void init(int n)
{
    for(int i=1;i<=n;i++)  st1[i][0]=st[i][0]=a[i];//��ʼ������i�㿪ʼ2^j���ȵļ�ֵ
    for(int j=1;j<20;j++)
        for(int i=1;i<=n;i++)
            if(i+(1<<(j-1))<n)
                st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]),
                st1[i][j]=max(st1[i][j-1],st1[i+(1<<(j-1))][j-1]); //��ֵ
}

int query(int l,int r)
{
    int len=log2(r-l+1);
    return max(st1[l][len],st1[r-(1<<len)+1][len])-min(st[l][len],st[r-(1<<len)+1][len]);
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);\
   int n,s,len; cin>>n>>>s>>len;

    for(int i=1;i<=n;i++) cin>>a[i];
    init(n);
    int l,r;
    if(len>n||query(1,len)>s) return cout<<-1<<endl,0;
    memset(dp,inf,sizeof(dp)); dp[0]=0;

}
*/


#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair

const int N=1e7+10;
const long long INF=1e18;
const double eps=0.0000001;
const ll mod=1e9+7;
int n,m,x,y,t;

int a[N],b[N];
string str;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       cin>>n>>m;
       bool vis[n][m];
       for(int i=0;i<n;i++)
       {
           cin>>str;
           for(int j=0;j<m;j++)
           {
               if(str[j]=='*')
                a[j]++,b[i]++;
               if(str[j]=='.')
                vis[i][j]=1;
           }
       }
       sort(a,a+m);
       sort(b,b+n);
       int flag=0;
       for(int i=n-1;i>=0;i--)
       {
           if(b[i]==b[n-1])
           {
               for(int j=m-1;j>=0;j--)
               {
                   if(a[j]==a[m-1])
                   {
                       if(vis[i][j]==1)
                       {
                           flag=1;
                           break;
                       }
                   }
                   else
                    break;
               }
           }
           else break;
       }
        if(flag==0)
            cout<<n+m-(a[m-1]+b[n-1])<<endl;
        else
            cout<<n+m-(a[m-1]+b[n-1])-1<<endl;
    }
}

/*
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<stack>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

const int maxn=1e5+7;
int st[maxn][20],st1[maxn][20],a[maxn],n;

void init(int n)
{
    for(int i=1;i<=n;i++)  st1[i][0]=st[i][0]=a[i];//初始化，从i点开始2^j长度的极值
    for(int j=1;j<20;j++)
        for(int i=1;i<=n;i++)
            if(i+(1<<(j-1))<n)
                st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]),
                st1[i][j]=max(st1[i][j-1],st1[i+(1<<(j-1))][j-1]); //最值
}

int query(int l,int r)
{
    int len=log2(r-l+1);
    return max(st1[l][len],st1[r-(1<<len)+1][len])-min(st[l][len],st[r-(1<<len)+1][len]);
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);\
   int n,s,len; cin>>n>>>s>>len;

    for(int i=1;i<=n;i++) cin>>a[i];
    init(n);
    int l,r;
    if(len>n||query(1,len)>s) return cout<<-1<<endl,0;
    memset(dp,inf,sizeof(dp)); dp[0]=0;

}
*/


#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair

const int N=1e7+10;
const long long INF=1e18;
const double eps=0.0000001;
const ll mod=1e9+7;
int n,m,x,y,t;

struct note
{
    int x,id;
}a[N],b[N];
string str[N];

bool cmp(note a,note b)
{
    return a.x<b.x;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       cin>>n>>m;
       for(int i=0;i<n;i++)
       {
           cin>>str[i];
           for(int j=0;j<m;j++)
           {
               if(str[i][j]=='*')
                a[j].x++,a[j].id=j,b[i].x++,b[i].id=i;
           }
       }
       sort(a,a+m,cmp);
       sort(b,b+n,cmp);
       int flag=0;
       for(int i=n-1;i>=0;i--)
       {
           if(b[i].x==b[n-1].x)
           {
               for(int j=m-1;j>=0;j--)
               {
                   if(a[j].x==a[m-1].x)
                   {
                       if(str[b[i].id][a[j].id]=='.')
                       {
                           flag=1;
                           //cout<<i<<" "<<j;
                           break;
                       }
                   }
                   else
                    break;
               }
           }
           else break;
       }
        if(flag==0)
            cout<<n+m-(a[m-1].x+b[n-1].x)<<endl;
        else
            cout<<n+m-(a[m-1].x+b[n-1].x)-1<<endl;
    }
}


#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair

const int N=1e7+10;
const long long INF=1e18;
const double eps=0.0000001;
const ll mod=1e9+7;
int n,m,x,y,t;

struct note
{
    int x,id;
}a[N],b[N];

bool cmp(note a,note b)
{
    return a.x<b.x;
}
char str[N];

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    scanf("%d",&t);
    while(t--)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       scanf("%d%d",&n,&m);
       int vis[n][m];
       memset(vis,0,sizeof(vis));
       for(int i=0;i<n;i++)
       {
           scanf("%s",str);
           for(int j=0;j<m;j++)
           {
               if(str[j]=='*')
                a[j].x++,a[j].id=j,b[i].x++,b[i].id=i;
               if(str[j]=='.')
                vis[i][j]=1;
           }
       }
       int flag=0,ans=N;
       for(int i=n-1;i>=0;i--)
       {
               for(int j=m-1;j>=0;j--)
               {
                       flag=0;
                       if(vis[i][j]==1)
                       {
                           flag=1;
                       }
                       if(flag==0)
                            ans=min(n+m-(a[j].x+b[i].x),ans);
                       else
                            ans=min(n+m-(a[j].x+b[i].x)-1,ans);

               }

       }

       printf("%d\n",ans);
    }
}

/*
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<stack>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

const int maxn=1e5+7;
int st[maxn][20],st1[maxn][20],a[maxn],n;

void init(int n)
{
    for(int i=1;i<=n;i++)  st1[i][0]=st[i][0]=a[i];//初始化，从i点开始2^j长度的极值
    for(int j=1;j<20;j++)
        for(int i=1;i<=n;i++)
            if(i+(1<<(j-1))<n)
                st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]),
                st1[i][j]=max(st1[i][j-1],st1[i+(1<<(j-1))][j-1]); //最值
}

int query(int l,int r)
{
    int len=log2(r-l+1);
    return max(st1[l][len],st1[r-(1<<len)+1][len])-min(st[l][len],st[r-(1<<len)+1][len]);
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);\
   int n,s,len; cin>>n>>>s>>len;

    for(int i=1;i<=n;i++) cin>>a[i];
    init(n);
    int l,r;
    if(len>n||query(1,len)>s) return cout<<-1<<endl,0;
    memset(dp,inf,sizeof(dp)); dp[0]=0;

}
*/


#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair

const int N=1e7+10;
const long long INF=1e18;
const double eps=0.0000001;
const ll mod=1e9+7;
int n,m,x,y,t;

struct note
{
    int x,id;
}a[N],b[N];

bool cmp(note a,note b)
{
    return a.x<b.x;
}
string str;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       cin>>n>>m;
       int vis[n][m]={0};
       for(int i=0;i<n;i++)
       {
           cin>>str;
           for(int j=0;j<m;j++)
           {
               if(str[j]=='*')
                a[j].x++,a[j].id=j,b[i].x++,b[i].id=i;
               if(str[j]=='.')
                vis[i][j]=1;
           }
       }
       sort(a,a+m,cmp);
       sort(b,b+n,cmp);
       int flag=0;
       for(int i=n-1;i>=0;i--)
       {
           if(b[i].x==b[n-1].x)
           {
               for(int j=m-1;j>=0;j--)
               {
                   if(a[j].x==a[m-1].x)
                   {
                       if(vis[b[i].id][a[j].id]==1)
                       {

                           flag=1;
                           //cout<<i<<" "<<j;
                           break;
                       }
                   }
                   else
                    break;
               }
           }
           else break;
       }
        if(flag==0)
            cout<<n+m-(a[m-1].x+b[n-1].x)<<endl;
        else
            cout<<n+m-(a[m-1].x+b[n-1].x)-1<<endl;
    }
}

/*
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<stack>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

const int maxn=1e5+7;
int st[maxn][20],st1[maxn][20],a[maxn],n;

void init(int n)
{
    for(int i=1;i<=n;i++)  st1[i][0]=st[i][0]=a[i];//��ʼ������i�㿪ʼ2^j���ȵļ�ֵ
    for(int j=1;j<20;j++)
        for(int i=1;i<=n;i++)
            if(i+(1<<(j-1))<n)
                st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]),
                st1[i][j]=max(st1[i][j-1],st1[i+(1<<(j-1))][j-1]); //��ֵ
}

int query(int l,int r)
{
    int len=log2(r-l+1);
    return max(st1[l][len],st1[r-(1<<len)+1][len])-min(st[l][len],st[r-(1<<len)+1][len]);
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);\
   int n,s,len; cin>>n>>>s>>len;

    for(int i=1;i<=n;i++) cin>>a[i];
    init(n);
    int l,r;
    if(len>n||query(1,len)>s) return cout<<-1<<endl,0;
    memset(dp,inf,sizeof(dp)); dp[0]=0;

}
*/


#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair

const int N=1e7+10;
const long long INF=1e18;
const double eps=0.0000001;
const ll mod=1e9+7;
int n,m,x,y,t;

struct note
{
    int x,id;
}a[N],b[N];

bool cmp(note a,note b)
{
    return a.x<b.x;
}
string str;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       cin>>n>>m;
       bool vis[n][m];
       for(int i=0;i<n;i++)
       {
           cin>>str;
           for(int j=0;j<m;j++)
           {
               if(str[j]=='*')
                a[j].x++,a[j].id=j,b[i].x++,b[i].id=i;
               if(str[j]=='.')
                vis[i][j]=1;
           }
       }
       sort(a,a+m,cmp);
       sort(b,b+n,cmp);
       int flag=0;
       for(int i=n-1;i>=0;i--)
       {
           if(b[i].x==b[n-1].x)
           {
               for(int j=m-1;j>=0;j--)
               {
                   if(a[j].x==a[m-1].x)
                   {
                       if(vis[b[i].id][a[j].id]==1)
                       {
                           flag=1;
                           //cout<<i<<" "<<j;
                           break;
                       }
                   }
                   else
                    break;
               }
           }
           else break;
       }
        if(flag==0)
            cout<<n+m-(a[m-1].x+b[n-1].x)<<endl;
        else
            cout<<n+m-(a[m-1].x+b[n-1].x)-1<<endl;
    }
}

/*
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<stack>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

const int maxn=1e5+7;
int st[maxn][20],st1[maxn][20],a[maxn],n;

void init(int n)
{
    for(int i=1;i<=n;i++)  st1[i][0]=st[i][0]=a[i];//��ʼ������i�㿪ʼ2^j���ȵļ�ֵ
    for(int j=1;j<20;j++)
        for(int i=1;i<=n;i++)
            if(i+(1<<(j-1))<n)
                st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]),
                st1[i][j]=max(st1[i][j-1],st1[i+(1<<(j-1))][j-1]); //��ֵ
}

int query(int l,int r)
{
    int len=log2(r-l+1);
    return max(st1[l][len],st1[r-(1<<len)+1][len])-min(st[l][len],st[r-(1<<len)+1][len]);
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);\
   int n,s,len; cin>>n>>>s>>len;

    for(int i=1;i<=n;i++) cin>>a[i];
    init(n);
    int l,r;
    if(len>n||query(1,len)>s) return cout<<-1<<endl,0;
    memset(dp,inf,sizeof(dp)); dp[0]=0;

}
*/


#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair

const int N=5e4+10;
const long long INF=1e18;
const double eps=0.0000001;
const ll mod=1e9+7;
int n,m,x,y,t;

int a[N],b[N];

char str[N];

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    scanf("%d",&t);
    while(t--)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       scanf("%d%d",&n,&m);
       int vis[n][m];
       memset(vis,0,sizeof(vis));//初始化
       for(int i=0;i<n;i++)
       {
           scanf("%s",str);
           for(int j=0;j<m;j++)
           {
               if(str[j]=='*')
                a[j]++,b[i]++;
               if(str[j]=='.')
                vis[i][j]=1;
           }
       }
       int flag=0,ans=N;
       for(int i=0;i<n;i++)
       {
               for(int j=0;j<=m;j++)
               {
                       flag=0;
                       if(vis[i][j]==1)
                       {
                           flag=1;
                       }
                       if(flag==0)
                            ans=min(n+m-(a[j]+b[i]),ans);
                       else
                            ans=min(n+m-(a[j]+b[i])-1,ans);
                       //if(ans==0)
                       //   break;

               }
               //if(ans==0)
               // break;

       }

       printf("%d\n",ans);
    }
}

/*
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<stack>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

const int maxn=1e5+7;
int st[maxn][20],st1[maxn][20],a[maxn],n;

void init(int n)
{
    for(int i=1;i<=n;i++)  st1[i][0]=st[i][0]=a[i];//初始化，从i点开始2^j长度的极值
    for(int j=1;j<20;j++)
        for(int i=1;i<=n;i++)
            if(i+(1<<(j-1))<n)
                st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]),
                st1[i][j]=max(st1[i][j-1],st1[i+(1<<(j-1))][j-1]); //最值
}

int query(int l,int r)
{
    int len=log2(r-l+1);
    return max(st1[l][len],st1[r-(1<<len)+1][len])-min(st[l][len],st[r-(1<<len)+1][len]);
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);\
   int n,s,len; cin>>n>>>s>>len;

    for(int i=1;i<=n;i++) cin>>a[i];
    init(n);
    int l,r;
    if(len>n||query(1,len)>s) return cout<<-1<<endl,0;
    memset(dp,inf,sizeof(dp)); dp[0]=0;

}
*/


#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair

const int N=1e7+10;
const long long INF=1e18;
const double eps=0.0000001;
const ll mod=1e9+7;
int n,m,x,y,t;

struct note
{
    int x,id;
}a[N],b[N];

bool cmp(note a,note b)
{
    return a.x<b.x;
}
string str;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       cin>>n>>m;
       int vis[n][m]={0};
       for(int i=0;i<n;i++)
       {
           cin>>str;
           for(int j=0;j<m;j++)
           {
               if(str[j]=='*')
                a[j].x++,a[j].id=j,b[i].x++,b[i].id=i;
               if(str[j]=='.')
                vis[i][j]=1;
           }
       }
       int flag=0,ans=N;
       for(int i=n-1;i>=0;i--)
       {
               for(int j=m-1;j>=0;j--)
               {
                       flag=0;
                       if(vis[i][j]==1)
                       {
                           flag=1;
                       }
                       if(flag==0)
                            ans=min(n+m-(a[j].x+b[i].x),ans);
                       else
                            ans=min(n+m-(a[j].x+b[i].x)-1,ans);

               }

       }
       cout<<ans<<endl;
    }
}

/*
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<stack>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

const int maxn=1e5+7;
int st[maxn][20],st1[maxn][20],a[maxn],n;

void init(int n)
{
    for(int i=1;i<=n;i++)  st1[i][0]=st[i][0]=a[i];//��ʼ������i�㿪ʼ2^j���ȵļ�ֵ
    for(int j=1;j<20;j++)
        for(int i=1;i<=n;i++)
            if(i+(1<<(j-1))<n)
                st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]),
                st1[i][j]=max(st1[i][j-1],st1[i+(1<<(j-1))][j-1]); //��ֵ
}

int query(int l,int r)
{
    int len=log2(r-l+1);
    return max(st1[l][len],st1[r-(1<<len)+1][len])-min(st[l][len],st[r-(1<<len)+1][len]);
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);\
   int n,s,len; cin>>n>>>s>>len;

    for(int i=1;i<=n;i++) cin>>a[i];
    init(n);
    int l,r;
    if(len>n||query(1,len)>s) return cout<<-1<<endl,0;
    memset(dp,inf,sizeof(dp)); dp[0]=0;

}
*/


#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair

const int N=1e7+10;
const long long INF=1e18;
const double eps=0.0000001;
const ll mod=1e9+7;
int n,m,x,y,t;

int a[N],b[N];
string str;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       cin>>n>>m;
       int vis[n][m];
       for(int i=0;i<n;i++)
       {
           cin>>str;
           for(int j=0;j<m;j++)
           {
               if(str[j]=='*')
                a[j]++,b[i]++;
               if(str[j]=='.')
                vis[i][j]=1;
           }
       }
       sort(a,a+m);
       sort(b,b+n);
       int flag=0;
       for(int i=n-1;i>=0;i--)
       {
           if(b[i]==b[n-1])
           {
               for(int j=m-1;j>=0;j--)
               {
                   if(a[j]==a[m-1])
                   {
                       if(vis[i][j]==1)
                       {
                           flag=1;
                           break;
                       }
                   }
                   else
                    break;
               }
           }
           else break;
       }
        if(flag==0)
            cout<<n+m-(a[m-1]+b[n-1])<<endl;
        else
            cout<<n+m-(a[m-1]+b[n-1])-1<<endl;
    }
}

/*
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<stack>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

const int maxn=1e5+7;
int st[maxn][20],st1[maxn][20],a[maxn],n;

void init(int n)
{
    for(int i=1;i<=n;i++)  st1[i][0]=st[i][0]=a[i];//初始化，从i点开始2^j长度的极值
    for(int j=1;j<20;j++)
        for(int i=1;i<=n;i++)
            if(i+(1<<(j-1))<n)
                st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]),
                st1[i][j]=max(st1[i][j-1],st1[i+(1<<(j-1))][j-1]); //最值
}

int query(int l,int r)
{
    int len=log2(r-l+1);
    return max(st1[l][len],st1[r-(1<<len)+1][len])-min(st[l][len],st[r-(1<<len)+1][len]);
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);\
   int n,s,len; cin>>n>>>s>>len;

    for(int i=1;i<=n;i++) cin>>a[i];
    init(n);
    int l,r;
    if(len>n||query(1,len)>s) return cout<<-1<<endl,0;
    memset(dp,inf,sizeof(dp)); dp[0]=0;

}
*/


#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair

const int N=5e4+10;
const long long INF=1e18;
const double eps=0.0000001;
const ll mod=1e9+7;
int n,m,x,y,t;

int a[N],b[N];

char str[N];

int main()
{
    //ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    scanf("%d",&t);
    while(t--)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       scanf("%d%d",&n,&m);
       int vis[n][m];
       memset(vis,0,sizeof(vis));//��ʼ��
       for(int i=0;i<n;i++)
       {
           scanf("%s",str);
           for(int j=0;j<m;j++)
           {
               if(str[j]=='*')
                a[j]++,b[i]++;
               if(str[j]=='.')
                vis[i][j]=1;
           }
       }
       int flag=0,ans=N;
       for(int i=0;i<n;i++)
       {
               for(int j=0;j<=m;j++)
               {
                       flag=0;
                       if(vis[i][j]==1)
                       {
                           flag=1;
                       }
                       if(flag==0)
                            ans=min(n+m-(a[j]+b[i]),ans);
                       else
                            ans=min(n+m-(a[j]+b[i])-1,ans);
                       //if(ans==0)
                       //   break;

               }
               //if(ans==0)
               // break;

       }

       printf("%d\n",ans);
    }
}

/*
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<stack>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

const int maxn=1e5+7;
int st[maxn][20],st1[maxn][20],a[maxn],n;

void init(int n)
{
    for(int i=1;i<=n;i++)  st1[i][0]=st[i][0]=a[i];//��ʼ������i�㿪ʼ2^j���ȵļ�ֵ
    for(int j=1;j<20;j++)
        for(int i=1;i<=n;i++)
            if(i+(1<<(j-1))<n)
                st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]),
                st1[i][j]=max(st1[i][j-1],st1[i+(1<<(j-1))][j-1]); //��ֵ
}

int query(int l,int r)
{
    int len=log2(r-l+1);
    return max(st1[l][len],st1[r-(1<<len)+1][len])-min(st[l][len],st[r-(1<<len)+1][len]);
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);\
   int n,s,len; cin>>n>>>s>>len;

    for(int i=1;i<=n;i++) cin>>a[i];
    init(n);
    int l,r;
    if(len>n||query(1,len)>s) return cout<<-1<<endl,0;
    memset(dp,inf,sizeof(dp)); dp[0]=0;

}
*/


#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair

const int N=1e7+10;
const long long INF=1e18;
const double eps=0.0000001;
const ll mod=1e9+7;
int n,m,x,y,t;

struct note
{
    int x,id;
}a[N],b[N];

bool cmp(note a,note b)
{
    return a.x<b.x;
}
string str;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       cin>>n>>m;
       int vis[n][m]={0};
       for(int i=0;i<n;i++)
       {
           cin>>str;
           for(int j=0;j<m;j++)
           {
               if(str[j]=='*')
                a[j].x++,a[j].id=j,b[i].x++,b[i].id=i;
               if(str[j]=='.')
                vis[i][j]=1;
           }
       }
       int flag=0,ans=N;
       for(int i=n-1;i>=0;i--)
       {
               for(int j=m-1;j>=0;j--)
               {
                       flag=0;
                       if(vis[i][j]==1)
                       {
                           flag=1;
                       }
                       if(flag==0)
                            ans=min(n+m-(a[j].x+b[i].x),ans);
                       else
                            ans=min(n+m-(a[j].x+b[i].x)-1,ans);

               }

       }
       printf("%d\n",ans);
    }
}

/*
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<stack>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

const int maxn=1e5+7;
int st[maxn][20],st1[maxn][20],a[maxn],n;

void init(int n)
{
    for(int i=1;i<=n;i++)  st1[i][0]=st[i][0]=a[i];//��ʼ������i�㿪ʼ2^j���ȵļ�ֵ
    for(int j=1;j<20;j++)
        for(int i=1;i<=n;i++)
            if(i+(1<<(j-1))<n)
                st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]),
                st1[i][j]=max(st1[i][j-1],st1[i+(1<<(j-1))][j-1]); //��ֵ
}

int query(int l,int r)
{
    int len=log2(r-l+1);
    return max(st1[l][len],st1[r-(1<<len)+1][len])-min(st[l][len],st[r-(1<<len)+1][len]);
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);\
   int n,s,len; cin>>n>>>s>>len;

    for(int i=1;i<=n;i++) cin>>a[i];
    init(n);
    int l,r;
    if(len>n||query(1,len)>s) return cout<<-1<<endl,0;
    memset(dp,inf,sizeof(dp)); dp[0]=0;

}
*/


#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair

const int N=1e7+10;
const long long INF=1e18;
const double eps=0.0000001;
const ll mod=1e9+7;
int n,m,x,y,t;

struct note
{
    int x,id;
}a[N],b[N];

bool cmp(note a,note b)
{
    return a.x<b.x;
}
char str[N];

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    scanf("%d",&t);
    while(t--)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       scanf("%d%d",&n,&m);
       int vis[n][m]={0};
       for(int i=0;i<n;i++)
       {
           scanf("%s",str);
           for(int j=0;j<m;j++)
           {
               if(str[j]=='*')
                a[j].x++,a[j].id=j,b[i].x++,b[i].id=i;
               if(str[j]=='.')
                vis[i][j]=1;
           }
       }
       int flag=0,ans=N;
       for(int i=n-1;i>=0;i--)
       {
               for(int j=m-1;j>=0;j--)
               {
                       flag=0;
                       if(vis[i][j]==1)
                       {
                           flag=1;
                       }
                       if(flag==0)
                            ans=min(n+m-(a[j].x+b[i].x),ans);
                       else
                            ans=min(n+m-(a[j].x+b[i].x)-1,ans);

               }

       }
       printf("%d\n",ans);
    }
}

/*
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<stack>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

const int maxn=1e5+7;
int st[maxn][20],st1[maxn][20],a[maxn],n;

void init(int n)
{
    for(int i=1;i<=n;i++)  st1[i][0]=st[i][0]=a[i];//��ʼ������i�㿪ʼ2^j���ȵļ�ֵ
    for(int j=1;j<20;j++)
        for(int i=1;i<=n;i++)
            if(i+(1<<(j-1))<n)
                st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]),
                st1[i][j]=max(st1[i][j-1],st1[i+(1<<(j-1))][j-1]); //��ֵ
}

int query(int l,int r)
{
    int len=log2(r-l+1);
    return max(st1[l][len],st1[r-(1<<len)+1][len])-min(st[l][len],st[r-(1<<len)+1][len]);
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);\
   int n,s,len; cin>>n>>>s>>len;

    for(int i=1;i<=n;i++) cin>>a[i];
    init(n);
    int l,r;
    if(len>n||query(1,len)>s) return cout<<-1<<endl,0;
    memset(dp,inf,sizeof(dp)); dp[0]=0;

}
*/


#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair

const int N=5e4+10;
const long long INF=1e18;
const double eps=0.0000001;
const ll mod=1e9+7;
int n,m,x,y,t;

struct note
{
    int x,id;
}a[N],b[N];

bool cmp(note a,note b)
{
    return a.x<b.x;
}
string str;

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       cin>>n>>m;
       int vis[n][m];
       memset(vis,0,sizeof(vis));
       for(int i=0;i<n;i++)
       {
           cin>>str;
           for(int j=0;j<m;j++)
           {
               if(str[j]=='*')
                a[j].x++,a[j].id=j,b[i].x++,b[i].id=i;
               if(str[j]=='.')
                vis[i][j]=1;
           }
       }
       sort(a,a+m,cmp);
       sort(b,b+n,cmp);
       int flag=0;
       for(int i=n-1;i>=0;i--)
       {
           if(b[i].x==b[n-1].x)
           {
               for(int j=m-1;j>=0;j--)
               {
                   if(a[j].x==a[m-1].x)
                   {
                       if(vis[b[i].id][a[j].id]==1)
                       {

                           flag=1;
                           //cout<<i<<" "<<j;
                           break;
                       }
                   }
                   else
                    break;
               }
           }
           else break;
       }
        if(flag==0)
            cout<<n+m-(a[m-1].x+b[n-1].x)<<endl;
        else
            cout<<n+m-(a[m-1].x+b[n-1].x)-1<<endl;
    }
}

/*
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<stack>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

const int maxn=1e5+7;
int st[maxn][20],st1[maxn][20],a[maxn],n;

void init(int n)
{
    for(int i=1;i<=n;i++)  st1[i][0]=st[i][0]=a[i];//��ʼ������i�㿪ʼ2^j���ȵļ�ֵ
    for(int j=1;j<20;j++)
        for(int i=1;i<=n;i++)
            if(i+(1<<(j-1))<n)
                st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]),
                st1[i][j]=max(st1[i][j-1],st1[i+(1<<(j-1))][j-1]); //��ֵ
}

int query(int l,int r)
{
    int len=log2(r-l+1);
    return max(st1[l][len],st1[r-(1<<len)+1][len])-min(st[l][len],st[r-(1<<len)+1][len]);
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);\
   int n,s,len; cin>>n>>>s>>len;

    for(int i=1;i<=n;i++) cin>>a[i];
    init(n);
    int l,r;
    if(len>n||query(1,len)>s) return cout<<-1<<endl,0;
    memset(dp,inf,sizeof(dp)); dp[0]=0;

}
*/


#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair

const int N=1e6+10;
const long long INF=1e18;
const double eps=0.0000001;
const ll mod=1e9+7;
int n,m,x,y,t;

int a[N],b[N];

char str[N];

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    scanf("%d",&t);
    while(t--)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       scanf("%d%d",&n,&m);
       int vis[n][m];
       memset(vis,0,sizeof(vis));//��ʼ��
       for(int i=0;i<n;i++)
       {
           scanf("%s",str);
           for(int j=0;j<m;j++)
           {
               if(str[j]=='*')
                a[j]++,b[i]++;
               if(str[j]=='.')
                vis[i][j]=1;
           }
       }
       int flag=0,ans=N;
       for(int i=n-1;i>=0;i--)
       {
               for(int j=m-1;j>=0;j--)
               {
                       flag=0;
                       if(vis[i][j]==1)
                       {
                           flag=1;
                       }
                       if(flag==0)
                            ans=min(n+m-(a[j]+b[i]),ans);
                       else
                            ans=min(n+m-(a[j]+b[i])-1,ans);

               }

       }

       printf("%d\n",ans);
    }
}

/*
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<stack>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

const int maxn=1e5+7;
int st[maxn][20],st1[maxn][20],a[maxn],n;

void init(int n)
{
    for(int i=1;i<=n;i++)  st1[i][0]=st[i][0]=a[i];//��ʼ������i�㿪ʼ2^j���ȵļ�ֵ
    for(int j=1;j<20;j++)
        for(int i=1;i<=n;i++)
            if(i+(1<<(j-1))<n)
                st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]),
                st1[i][j]=max(st1[i][j-1],st1[i+(1<<(j-1))][j-1]); //��ֵ
}

int query(int l,int r)
{
    int len=log2(r-l+1);
    return max(st1[l][len],st1[r-(1<<len)+1][len])-min(st[l][len],st[r-(1<<len)+1][len]);
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);\
   int n,s,len; cin>>n>>>s>>len;

    for(int i=1;i<=n;i++) cin>>a[i];
    init(n);
    int l,r;
    if(len>n||query(1,len)>s) return cout<<-1<<endl,0;
    memset(dp,inf,sizeof(dp)); dp[0]=0;

}
*/


#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair

const int N=1e7+10;
const long long INF=1e18;
const double eps=0.0000001;
const ll mod=1e9+7;
int n,m,x,y,t;

struct note
{
    int x,id;
}a[N],b[N];

bool cmp(note a,note b)
{
    return a.x<b.x;
}
char str[N];

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    scanf("%d",&t);
    while(t--)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       scanf("%d%d",&n,&m);
       int vis[n][m]={0};
       for(int i=0;i<n;i++)
       {
           scanf("%s",str);
           for(int j=0;j<m;j++)
           {
               if(str[j]=='*')
                a[j].x++,a[j].id=j,b[i].x++,b[i].id=i;
               if(str[j]=='.')
                vis[i][j]=1;
           }
       }
       int flag=0,ans=N;
       for(int i=n-1;i>=0;i--)
       {
               for(int j=m-1;j>=0;j--)
               {
                       flag=0;
                       if(vis[i][j]==1)
                       {
                           flag=1;
                       }
                       if(flag==0)
                            ans=min(n+m-(a[j].x+b[i].x),ans);
                       else
                            ans=min(n+m-(a[j].x+b[i].x)-1,ans);

               }

       }

       printf("%d\n",ans);
    }
}

/*
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<stack>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

const int maxn=1e5+7;
int st[maxn][20],st1[maxn][20],a[maxn],n;

void init(int n)
{
    for(int i=1;i<=n;i++)  st1[i][0]=st[i][0]=a[i];//初始化，从i点开始2^j长度的极值
    for(int j=1;j<20;j++)
        for(int i=1;i<=n;i++)
            if(i+(1<<(j-1))<n)
                st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]),
                st1[i][j]=max(st1[i][j-1],st1[i+(1<<(j-1))][j-1]); //最值
}

int query(int l,int r)
{
    int len=log2(r-l+1);
    return max(st1[l][len],st1[r-(1<<len)+1][len])-min(st[l][len],st[r-(1<<len)+1][len]);
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);\
   int n,s,len; cin>>n>>>s>>len;

    for(int i=1;i<=n;i++) cin>>a[i];
    init(n);
    int l,r;
    if(len>n||query(1,len)>s) return cout<<-1<<endl,0;
    memset(dp,inf,sizeof(dp)); dp[0]=0;

}
*/


#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair

const int N=1e7+10;
const long long INF=1e18;
const double eps=0.0000001;
const ll mod=1e9+7;
int n,m,x,y,t;
/*
struct note
{
    int x,id;
}a[N],b[N];bool cmp(note a,note b)
{
    return a.x<b.x;
}*/
int a[30],b[30];
string str1,str2,str3 ;

bool contains(string t, string s) {
	int i = 0;
	for (char c : s) {
		if (i == t.size()) return false;
		while (i < t.size() && c != t[i]) {
			i++;
		}
		i++;
	}
	return i <= t.size();
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin>>t;
    while(t--)
    {
        memset(a,0,sizeof(a));
        memset(b,0,sizeof(b));
        vector<int>q[30],p[30];
        cin>>str1>>str2>>str3;
        for(int i=0;i<str1.size();i++)
        {
            q[str1[i]-'a'].push_back(i);
            a[str1[i]-'a']++;
        }
        for(int i=0;i<str2.size();i++)
        {
            p[str2[i]-'a'].push_back(i);
            b[str2[i]-'a']++;
        }
        for(int i=0;i<str3.size();i++)
        {
            a[str3[i]-'a']++;
        }
        int flag=0;
        /*
        for(int i=0;i<26;i++)
        {
            while(q[i].size())
            {
                if(!p[i].size())
                {
                    flag=1;break;
                }
                else if(q[i].back()<=p[i].back())
                    q[i].erase(q[i].end()-1),p[i].erase(p[i].end()-1);
                else
                {
                    flag=1;break;
                }
            }
            if(flag==1) break;

        }
        */
        flag=!contains(str2, str1);
        if(flag==1)
            cout<<"NO"<<endl;
        else
        {
            for(int i=0;i<26;i++)
            {
                if(a[i]<b[i])
                {
                    flag=1;break;
                }
            }
            if(flag==1) cout<<"NO"<<endl;
            else cout<<"YES"<<endl;
        }
    }
    /*cin>>t;
    while(t--)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       cin>>n>>m;
       for(int i=0;i<n;i++)
       {
           cin>>str;
           for(int j=0;j<m;j++)
           {
               if(str[j]=='*')
                a[j].x++,b[i].x++;
               if(str[j]=='.')
                a[j].id++,b[i].id++;
           }
       }
       sort(a,a+m,cmp);
       sort(b,b+n,cmp);
       int flag=0;
       for(int i=n-1;i>=0;i--)
       {
           if(b[i].x==b[n-1].x)
           {
               for(int j=m-1;j>=0;j--)
               {
                   if(a[j].x==a[m-1].x)
                   {
                       if()
                       {
                           flag=1;
                           //cout<<i<<" "<<j;
                           break;
                       }
                   }
                   else
                    break;
               }
           }
           else break;
       }
        if(flag==0)
            cout<<n+m-(a[m-1].x+b[n-1].x)<<endl;
        else
            cout<<n+m-(a[m-1].x+b[n-1].x)-1<<endl;
    }*/
}

/*
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<stack>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

const int maxn=1e5+7;
int st[maxn][20],st1[maxn][20],a[maxn],n;

void init(int n)
{
    for(int i=1;i<=n;i++)  st1[i][0]=st[i][0]=a[i];//初始化，从i点开始2^j长度的极值
    for(int j=1;j<20;j++)
        for(int i=1;i<=n;i++)
            if(i+(1<<(j-1))<n)
                st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]),
                st1[i][j]=max(st1[i][j-1],st1[i+(1<<(j-1))][j-1]); //最值
}

int query(int l,int r)
{
    int len=log2(r-l+1);
    return max(st1[l][len],st1[r-(1<<len)+1][len])-min(st[l][len],st[r-(1<<len)+1][len]);
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);\
   int n,s,len; cin>>n>>>s>>len;

    for(int i=1;i<=n;i++) cin>>a[i];
    init(n);
    int l,r;
    if(len>n||query(1,len)>s) return cout<<-1<<endl,0;
    memset(dp,inf,sizeof(dp)); dp[0]=0;

}
*/


#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
#define mp make_pair

const int N=5e4+10;
const long long INF=1e18;
const double eps=0.0000001;
const ll mod=1e9+7;
int n,m,x,y,t;

int a[N],b[N];

char str[N];

int main()
{
    //ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    scanf("%d",&t);
    while(t--)
    {
       memset(a,0,sizeof(a));
       memset(b,0,sizeof(b));
       scanf("%d%d",&n,&m);
       int vis[n][m];
       memset(vis,0,sizeof(vis));//��ʼ��
       for(int i=0;i<n;i++)
       {
           scanf("%s",str);
           for(int j=0;j<m;j++)
           {
               if(str[j]=='*')
                a[j]++,b[i]++;
               if(str[j]=='.')
                vis[i][j]=1;
           }
       }
       int flag=0,ans=N;
       for(int i=0;i<n;i++)
       {
               for(int j=0;j<=m;j++)
               {
                       flag=0;
                       if(vis[i][j]==1)
                       {
                           flag=1;
                       }
                       if(flag==0)
                            ans=min(n+m-(a[j]+b[i]),ans);
                       else
                            ans=min(n+m-(a[j]+b[i])-1,ans);
                       if(ans==0)
                          break;

               }
               if(ans==0)
                break;

       }

       printf("%d\n",ans);
    }
}

/*
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<iostream>
#include<cstring>
#include<functional>
#include<set>
#include<map>
#include<stack>
#include<iterator>
#include<queue>
#include<vector>
#include<string>
using namespace std;

const int maxn=1e5+7;
int st[maxn][20],st1[maxn][20],a[maxn],n;

void init(int n)
{
    for(int i=1;i<=n;i++)  st1[i][0]=st[i][0]=a[i];//��ʼ������i�㿪ʼ2^j���ȵļ�ֵ
    for(int j=1;j<20;j++)
        for(int i=1;i<=n;i++)
            if(i+(1<<(j-1))<n)
                st[i][j]=min(st[i][j-1],st[i+(1<<(j-1))][j-1]),
                st1[i][j]=max(st1[i][j-1],st1[i+(1<<(j-1))][j-1]); //��ֵ
}

int query(int l,int r)
{
    int len=log2(r-l+1);
    return max(st1[l][len],st1[r-(1<<len)+1][len])-min(st[l][len],st[r-(1<<len)+1][len]);
}

int main()
{
   ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);\
   int n,s,len; cin>>n>>>s>>len;

    for(int i=1;i<=n;i++) cin>>a[i];
    init(n);
    int l,r;
    if(len>n||query(1,len)>s) return cout<<-1<<endl,0;
    memset(dp,inf,sizeof(dp)); dp[0]=0;

}
*/


// वाह मोदी जी वाह!

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> p64;
typedef vector<ll> v64;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main()
{
    // DANGER;
    ofstream out("output.txt");

    auto start = chrono::high_resolution_clock::now();

    ll t;
    cin>>t;
    rep(test,0,t-1)
    {
        ll n, m;
        cin>>n>>m;
        string s[n];
        rep(i,0,n-1) cin>>s[i];
        ll ind = 0, val = m;
        rep(i,0,n-1)
        {
            ll cnt = 0;
            rep(j,0,m-1) if( s[i][j]=='*' ) cnt++;
            if( m-cnt<val ) val = m-cnt, ind = i;
        }
        ll ans = val;
        // cout<<ind<<"\n";
        rep(i,0,m-1) s[ind][i] = '*';
        ind = 0, val = n;
        rep(i,0,m-1)
        {
            ll cnt = 0;
            rep(j,0,n-1) if( s[j][i]=='*' ) cnt++;
            if( n-cnt<val ) val = n-cnt, ind = i;
        }
        ans += val;
        cout<<ans<<"\n";
    }

    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}


// वाह मोदी जी वाह!

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> p64;
typedef vector<ll> v64;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main()
{
    // DANGER;
    ofstream out("output.txt");

    auto start = chrono::high_resolution_clock::now();

    ll t;
    cin>>t;
    rep(test,0,t-1)
    {
        ll n, m;
        cin>>n>>m;
        string s[n];
        rep(i,0,n-1) cin>>s[i];
        ll ind = 0, val = m;
        ll haha[n];
        mem( haha,0 );
        rep(i,0,n-1)
        {
            ll cnt = 0;
            rep(j,0,m-1) if( s[i][j]=='*' ) cnt++;
            haha[i] = cnt;
            if( m-cnt<val ) val = m-cnt, ind = i;
        }
        ll ans = val;
        bool mark[n];
        mem( mark,false );
        rep(i,0,n-1) if( haha[i]==m-val ) mark[i] = true;
        // cout<<ind<<"\n";
        // rep(i,0,m-1) s[ind][i] = '*';
        // bool fill = ans==0 ? false : true;
        val = n;
        // cout<<ans<<"\n";
        // for(auto i:mark) cout<<i<<" ";
        // cout<<endl;
        // ll fac = fill ? 1 : 0;
        rep(i,0,m-1)
        {
            ll cnt = 0;
            rep(j,0,n-1) if( s[j][i]=='*' || mark[j] ) cnt++;
            // cout<<cnt<<" ";
            // if( cnt==n )
            // {
            //     val = 0;
            //     break;
            // }
            if( n-cnt<val ) val = n-cnt;
        }
        // cout<<endl;
        ans += val;
        cout<<ans<<"\n";
    }

    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}


// वाह मोदी जी वाह!

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> p64;
typedef vector<ll> v64;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main()
{
    // DANGER;
    ofstream out("output.txt");

    auto start = chrono::high_resolution_clock::now();

    ll t;
    cin>>t;
    rep(test,0,t-1)
    {
        ll n, m;
        cin>>n>>m;
        string s[n], t[n];
        rep(i,0,n-1) cin>>s[i], t[i] = s[i];
        ll mn = 0;
        ll ind = 0, val = m;
        rep(i,0,n-1)
        {
            ll cnt = 0;
            rep(j,0,m-1) if( s[i][j]=='.' ) cnt++;
            if( cnt<val ) val = cnt, ind = i;
        }
        ll ans = val;
        // cout<<ind<<"\n";
        rep(i,0,m-1) s[ind][i] = '*';
        val = n;
        rep(i,0,m-1)
        {
            ll cnt = 0;
            rep(j,0,n-1) if( s[j][i]=='.' ) cnt++;
            if( cnt<val ) val = cnt;
        }
        ans += val;

        ind = 0, val = m;
        brep(i,n-1,0)
        {
            ll cnt = 0;
            rep(j,0,m-1) if( t[i][j]=='.' ) cnt++;
            if( cnt<val ) val = cnt, ind = i;
        }
        ll ans2 = val;
        // cout<<ind<<"\n";
        rep(i,0,m-1) t[ind][i] = '*';
        val = n;
        rep(i,0,m-1)
        {
            ll cnt = 0;
            rep(j,0,n-1) if( t[j][i]=='.' ) cnt++;
            if( cnt<val ) val = cnt;
        }
        ans2 += val;
        cout<<min(ans,ans2)<<endl;
    }

    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}


// वाह मोदी जी वाह!

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> p64;
typedef vector<ll> v64;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main()
{
    // DANGER;
    ofstream out("output.txt");

    auto start = chrono::high_resolution_clock::now();

    ll t;
    cin>>t;
    rep(test,0,t-1)
    {
        ll n, m;
        cin>>n>>m;
        string s[n];
        rep(i,0,n-1) cin>>s[i];
        ll ind = -1, val = m;
        rep(i,0,n-1)
        {
            ll cnt = 0;
            rep(j,0,m-1) if( s[i][j]=='*' ) cnt++;
            if( m-cnt<val ) val = m-cnt, ind = i;
        }
        ll ans = val;
        rep(i,0,m-1) s[ind][i] = '*';
        ind = -1, val = n;
        rep(i,0,m-1)
        {
            ll cnt = 0;
            rep(j,0,n-1) if( s[j][i]=='*' ) cnt++;
            if( n-cnt<val ) val = n-cnt, ind = i;
        }
        ans += val;
        cout<<ans<<"\n";
    }

    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}


// वाह मोदी जी वाह!

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> p64;
typedef vector<ll> v64;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main()
{
    // DANGER;
    ofstream out("output.txt");

    auto start = chrono::high_resolution_clock::now();

    ll t;
    cin>>t;
    rep(test,0,t-1)
    {
        ll n, m;
        cin>>n>>m;
        string s[n];
        rep(i,0,n-1) cin>>s[i];
        ll ind = -1, val = m;
        rep(i,0,n-1)
        {
            ll cnt = 0;
            rep(j,0,m-1) if( s[i][j]=='*' ) cnt++;
            if( m-cnt<=val ) val = m-cnt, ind = i;
        }
        ll ans = val;
        // cout<<ind<<"\n";
        rep(i,0,m-1) s[ind][i] = '*';
        ind = -1, val = n;
        rep(i,0,m-1)
        {
            ll cnt = 0;
            rep(j,0,n-1) if( s[j][i]=='*' ) cnt++;
            if( n-cnt<=val ) val = n-cnt, ind = i;
        }
        ans += val;
        cout<<ans<<"\n";
    }

    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}


// वाह मोदी जी वाह!

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> p64;
typedef vector<ll> v64;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(int i=s;i<=e;i++)
#define brep(i,s,e) for(int i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)

int main()
{
    // DANGER;
    ofstream out("output.txt");

    auto start = chrono::high_resolution_clock::now();

    ll t;
    cin>>t;
    rep(test,0,t-1)
    {
        ll n, m;
        cin>>n>>m;
        string s[n];
        rep(i,0,n-1) cin>>s[i];
        ll ind = 0, val = m;
        rep(i,0,n-1)
        {
            ll cnt = 0;
            rep(j,0,m-1) if( s[i][j]=='.' ) cnt++;
            if( cnt<val ) val = cnt, ind = i;
        }
        ll ans = val;
        // cout<<ind<<"\n";
        rep(i,0,m-1) s[ind][i] = '*';
        val = n;
        rep(i,0,m-1)
        {
            ll cnt = 0;
            rep(j,0,n-1) if( s[j][i]=='.' ) cnt++;
            if( cnt<val ) val = cnt;
        }
        ans += val;
        cout<<ans<<endl;
    }

    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}


/*
  "I knew I shouldn't have
   gotten out of bed today."
   - Squidward Tentacles
*/
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstring>
#include<climits>
#include<numeric>

#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<unordered_map>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#include<iomanip>
#include<fstream>
#include<chrono>
using namespace std;
using namespace __gnu_pbds;

#define int          long long
#define pii          pair<int,int>
#define vi           vector<int>
#define peque        priority_queue
#define pb           push_back
#define mp           make_pair
#define ff           first
#define ss           second
#define rep(i,s,e)   for(int i=s;i<=e;i++)
#define brep(i,s,e)  for(int i=s;i>=e;i--)
#define all(x)       x.begin(),x.end()
#define ball(x)      x.rbegin(),x.rend()
#define mem(x,y)     memset(x,y,sizeof(x))
#define oset         tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define VR46         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

signed main()
{
    VR46 ofstream out("output.txt");
    // auto start = chrono::high_resolution_clock::now();

    // GANDU THODE TEST CASE BNAKE TEST KRLE
    int t = 1;
    cin>>t;
    rep(test,1,t)
    {
        int n, m;
        cin>>n>>m;
        string s[n];
        rep(i,0,n-1) cin>>s[i];

        int row[n], col[m];
        rep(i,0,n-1)
        {
            int cnt = 0;
            for(auto j:s[i]) if( j=='.' ) cnt++;
            row[i] = cnt;
        }
        rep(i,0,m-1)
        {
            int cnt = 0;
            rep(j,0,n-1) if( s[j][i]=='.' ) cnt++;
            col[i] = cnt;
        }
        int sol = n*m;
        rep(i,0,n-1)
        {
            rep(j,0,m-1)
            {
                int rq = row[i]+col[j];
                if( s[i][j]=='.' ) rq--;
                sol = min( sol,rq );
            }
        }
        cout<<sol<<"\n";
    }

    // auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
    // cout<<"Time taken by function: "<<duration.count()<<" milliseconds"<<endl;
}


/*
  "I knew I shouldn't have
   gotten out of bed today."
   - Squidward Tentacles
*/
#include<iostream>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstring>
#include<climits>
#include<numeric>

#include<deque>
#include<queue>
#include<vector>
#include<map>
#include<unordered_map>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>

#include<iomanip>
#include<fstream>
#include<chrono>
using namespace std;
using namespace __gnu_pbds;

#define int          long long
#define pii          pair<int,int>
#define vi           vector<int>
#define peque        priority_queue
#define pb           push_back
#define mp           make_pair
#define ff           first
#define ss           second
#define rep(i,s,e)   for(int i=s;i<=e;i++)
#define brep(i,s,e)  for(int i=s;i>=e;i--)
#define all(x)       x.begin(),x.end()
#define ball(x)      x.rbegin(),x.rend()
#define mem(x,y)     memset(x,y,sizeof(x))
#define oset         tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define VR46         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

signed main()
{
    VR46 ofstream out("output.txt");
    // auto start = chrono::high_resolution_clock::now();

    // GANDU THODE TEST CASE BNAKE TEST KRLE
    int t = 1;
    cin>>t;
    rep(test,1,t)
    {
        int n, m;
        cin>>n>>m;
        // bool vis[n][m];
        // mem( vis,false );
        string s[n];
        rep(i,0,n-1) cin>>s[i];

        int mn = 0, idx = 0;
        rep(i,0,n-1)
        {
            int cnt = 0;
            for(auto j:s[i]) if( j=='*' ) cnt++;
            if( cnt>mn ) mn = cnt, idx = i;
        }

        int change = 0;
        for(auto &i:s[idx]) if( i=='.' ) i = '*', change++;

        mn = 0, idx = 0;
        rep(i,0,m-1)
        {
            int cnt = 0;
            rep(j,0,n-1) if( s[j][i]=='*' ) cnt++;
            if( cnt>mn ) mn = cnt, idx = i;
        }

        rep(i,0,n-1) if( s[i][idx]=='.' ) change++;

        cout<<change<<"\n";
    }

    // auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start);
    // cout<<"Time taken by function: "<<duration.count()<<" milliseconds"<<endl;
}


 #include<bits/stdc++.h>
using namespace std;
int main()
{
	int q;
	int n,m,i,j;
	cin>>q;
	while(q--){
		int hang=0,lie=0,count1=0,count2=0;
		int h,l;
    	cin>>n>>m;
    	char x[n+10][m+10];
    	getchar();
    	int ans;
    	for(i=1;i<=n;i++){
    		for(j=1;j<=m;j++){
    			scanf("%c",&x[i][j]);
    		}
    		getchar();
    	}
    	for(i=1;i<=n;i++){
    		count1=0;
    		for(j=1;j<=m;j++){
    			if(x[i][j]=='*') count1++;
    		}
    		if(hang<count1){
    			hang=count1;
    			h=i;
    		}
    	}
    	for(j=1;j<=m;j++){
    		count2=0;
    		for(i=1;i<=n;i++){
    			if(x[i][j]=='*') count2++;
    		}
    		if(lie<count2){
    			lie=count2;
    			l=j;
    		}
    	}
    	if(x[h][l]=='*') ans=n+m-1-(hang+lie-1);
    	else ans=n+m-1-(hang+lie);
    	cout<<ans<<endl;
	}
	return 0;
}


 #include<bits/stdc++.h>
using namespace std;
int main()
{
	int q;
	int n,m,i,j;
	cin>>q;
	while(q--){
		int hang=0,lie=0,count1=0,count2=0;
		int h,l;
    	cin>>n>>m;
    	char x[n+1][m+1];
    	int ans;
    	for(i=1;i<=n;i++){
    		for(j=1;j<=m;j++){
    			cin>>x[i][j];
    		}
    	}
    	for(i=1;i<=n;i++){
    		count1=0;
    		for(j=1;j<=m;j++){
    			if(x[i][j]=='*') count1++;
    		}
    		if(hang<count1){
    			hang=count1;
    			h=i;
    		}
    	}
    	for(j=1;j<=m;j++){
    		count2=0;
    		for(i=1;i<=n;i++){
    			if(x[i][j]=='*') count2++;
    		}
    		if(lie<count2){
    			lie=count2;
    			l=j;
    		}
    	}
    	if(x[h][l]=='*') ans=n+m-1-(hang+lie-1);
    	else ans=n+m-1-(hang+lie);
    	cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q;
	int n,m,i,j;
	char x[40000][40000];
	cin>>q;
	while(q--){
		int hang=0,lie=0,count1=0,count2=0;
		int h,l;
    	cin>>n>>m;
    	getchar();
    	int ans;
    	for(i=1;i<=n;i++){
    		for(j=1;j<=m;j++){
    			scanf("%c",&x[i][j]);
    		}
    		getchar();
    	}
    	for(i=1;i<=n;i++){
    		count1=0;
    		for(j=1;j<=m;j++){
    			if(x[i][j]=='*') count1++;
    		}
    		if(hang<count1){
    			hang=count1;
    			h=i;
    		}
    	}
    	for(j=1;j<=m;j++){
    		count2=0;
    		for(i=1;i<=n;i++){
    			if(x[i][j]=='*') count2++;
    		}
    		if(lie<count2){
    			lie=count2;
    			l=j;
    		}
    	}
    	if(x[h][l]=='*') ans=n+m-1-(hang+lie-1);
    	else ans=n+m-1-(hang+lie);
    	cout<<ans<<endl;
	}
	return 0;
}


 #include<bits/stdc++.h>
using namespace std;
int main()
{
	int q;
	int n,m,i,j;
	cin>>q;
	while(q--){
		int hang=0,lie=0,count1=0,count2=0;
		int h,l;
    	cin>>n>>m;
    	char x[n+1][m+1];
    	int ans=INT_MAX;
    	for(i=1;i<=n;i++){
    		for(j=1;j<=m;j++){
    			cin>>x[i][j];
    		}
    	}
    	for(i=1;i<=n;i++){
    		count1=0;
    		for(j=1;j<=m;j++){
    			if(x[i][j]=='*') count1++;
    		}
    		if(hang<count1){
    			hang=count1;
    			h=i;
    		}
    	}
    	for(j=1;j<=m;j++){
    		count2=0;
    		for(i=1;i<=n;i++){
    			if(x[i][j]=='*') count2++;
    		}
    		if(lie<count2){
    			lie=count2;
    			l=j;
    		}
    	}
    	if(x[h][l]=='*') ans=n+m-1-(hang+lie-1);
    	else ans=n+m-1-(hang+lie);
    	cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q;
	int n,m,i,j;
	cin>>q;
	while(q--){
		int hang=0,lie=0,count1=0,count2=0;
		int h,l;
    	cin>>n>>m;
    	int a=n,b=m;
    	char x[a][b];
    	getchar();
    	int ans;
    	for(i=1;i<=n;i++){
    		for(j=1;j<=m;j++){
    			scanf("%c",&x[i][j]);
    		}
    		getchar();
    	}
    	for(i=1;i<=n;i++){
    		count1=0;
    		for(j=1;j<=m;j++){
    			if(x[i][j]=='*') count1++;
    		}
    		if(hang<count1){
    			hang=count1;
    			h=i;
    		}
    	}
    	for(j=1;j<=m;j++){
    		count2=0;
    		for(i=1;i<=n;i++){
    			if(x[i][j]=='*') count2++;
    		}
    		if(lie<count2){
    			lie=count2;
    			l=j;
    		}
    	}
    	if(x[h][l]=='*') ans=n+m-1-(hang+lie-1);
    	else ans=n+m-1-(hang+lie);
    	cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q;
	int n,m,i,j;
	cin>>q;
	while(q--){
		int hang=0,lie=0,count1=0,count2=0;
		int h,l;
    	cin>>n>>m;
    	char x[n+1][m+1];
    	int ans=0;
    	for(i=1;i<=n;i++){
    		for(j=1;j<=m;j++){
    			cin>>x[i][j];
    		}
    	}
    	if(n==1&&m==1&&x[n][m]=='.'){
    		cout<<1<<endl;
    		continue;
    	}
    	for(i=1;i<=n;i++){
    		count1=0;
    		for(j=1;j<=m;j++){
    			if(x[i][j]=='*') count1++;
    		}
    		if(hang<count1){
    			hang=count1;
    			h=i;
    		}
    	}
    	for(j=1;j<=m;j++){
    		count2=0;
    		for(i=1;i<=n;i++){
    			if(x[i][j]=='*') count2++;
    		}
    		if(lie<count2){
    			lie=count2;
    			l=j;
    		}
    	}
    	if(x[h][l]=='*') ans=n+m-(hang+lie);
    	else ans=n+m-1-(hang+lie);
    	cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q;
	int n,m,i,j;
	char x[10000][10000];
	cin>>q;
	while(q--){
		int hang=0,lie=0,count1=0,count2=0;
		int h,l;
    	cin>>n>>m;
    	getchar();
    	int ans;
    	for(i=1;i<=n;i++){
    		for(j=1;j<=m;j++){
    			scanf("%c",&x[i][j]);
    		}
    		getchar();
    	}
    	for(i=1;i<=n;i++){
    		count1=0;
    		for(j=1;j<=m;j++){
    			if(x[i][j]=='*') count1++;
    		}
    		if(hang<count1){
    			hang=count1;
    			h=i;
    		}
    	}
    	for(j=1;j<=m;j++){
    		count2=0;
    		for(i=1;i<=n;i++){
    			if(x[i][j]=='*') count2++;
    		}
    		if(lie<count2){
    			lie=count2;
    			l=j;
    		}
    	}
    	if(x[h][l]=='*') ans=n+m-1-(hang+lie-1);
    	else ans=n+m-1-(hang+lie);
    	cout<<ans<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
	int q;
	int n,m,i,j;
	char x[50001][50001];
	cin>>q;
	while(q--){
		int hang=0,lie=0,count1=0,count2=0;
		int h,l;
    	cin>>n>>m;
    	getchar();
    	int ans;
    	for(i=1;i<=n;i++){
    		for(j=1;j<=m;j++){
    			scanf("%c",&x[i][j]);
    		}
    		getchar();
    	}
    	for(i=1;i<=n;i++){
    		count1=0;
    		for(j=1;j<=m;j++){
    			if(x[i][j]=='*') count1++;
    		}
    		if(hang<count1){
    			hang=count1;
    			h=i;
    		}
    	}
    	for(j=1;j<=m;j++){
    		count2=0;
    		for(i=1;i<=n;i++){
    			if(x[i][j]=='*') count2++;
    		}
    		if(lie<count2){
    			lie=count2;
    			l=j;
    		}
    	}
    	if(x[h][l]=='*') ans=n+m-1-(hang+lie-1);
    	else ans=n+m-1-(hang+lie);
    	cout<<ans<<endl;
	}
	return 0;
}


 #include<bits/stdc++.h>
using namespace std;
int main()
{
	int q;
	int n,m,i,j;
	cin>>q;
	while(q--){
		int hang=0,lie=0,count1=0,count2=0;
		int h,l;
    	cin>>n>>m;
    	char x[n+1][m+1];
    	int ans=0;
    	for(i=1;i<=n;i++){
    		for(j=1;j<=m;j++){
    			cin>>x[i][j];
    		}
    	}
    	if(n==1&&m==1&&x[n][m]=='.'){
    		cout<<1<<endl;
    		continue;
    	}
    	for(i=1;i<=n;i++){
    		count1=0;
    		for(j=1;j<=m;j++){
    			if(x[i][j]=='*') count1++;
    		}
    		if(hang<count1){
    			hang=count1;
    			h=i;
    		}
    	}
    	for(j=1;j<=m;j++){
    		count2=0;
    		for(i=1;i<=n;i++){
    			if(x[i][j]=='*') count2++;
    		}
    		if(lie<count2){
    			lie=count2;
    			l=j;
    		}
    	}
    	if(x[h][l]=='*') ans=n+m-1-(hang+lie-1);
    	else ans=n+m-1-(hang+lie);
    	cout<<ans<<endl;
	}
	return 0;
}


 #include<bits/stdc++.h>
using namespace std;
int main()
{
	int q;
	int n,m,i,j;
	cin>>q;
	while(q--){
		int hang=0,lie=0,count1=0,count2=0;
		int h,l;
    	cin>>n>>m;
    	char x[n+1][m+1];
    	int ans=0;
    	for(i=1;i<=n;i++){
    		for(j=1;j<=m;j++){
    			cin>>x[i][j];
    		}
    	}
    	for(i=1;i<=n;i++){
    		count1=0;
    		for(j=1;j<=m;j++){
    			if(x[i][j]=='*') count1++;
    		}
    		if(hang<count1){
    			hang=count1;
    			h=i;
    		}
    	}
    	for(j=1;j<=m;j++){
    		count2=0;
    		for(i=1;i<=n;i++){
    			if(x[i][j]=='*') count2++;
    		}
    		if(lie<count2){
    			lie=count2;
    			l=j;
    		}
    	}
    	if(x[h][l]=='*') ans=n+m-1-(hang+lie-1);
    	else ans=n+m-1-(hang+lie);
    	cout<<ans<<endl;
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T>
class MinPq: public priority_queue<T, vector<T>, greater<T> > {};
template <typename T>
class MaxPq: public priority_queue<T, vector<T>, less<T> > {};

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define sqrti(n) (int)ceil(sqrt((double)n))
#define len(a) sizeof(a)/sizeof(a[0])
#define pcase(ca,v) cout<<"Case #"<<ca+1<<": "<<v<<'\n'
#define parity(n) (n&1)
#define even(n) parity(n)==0
#define odd(n) parity(n)==1
#define inf INT_MAX
#define infl LLONG_MAX

void solve(){
  int n, k, total=0;
  string s, ans;
  cin>>n>>k>>s;
  vector<vector<char>> dp(k, vector<char>(256));
  for(int i=0; i<n; i++){
    ans+=s[i];
    dp[i%k][s[i]]++;
  }
  for(int i=0; i<n; i+=k){
    int l=i, r=i+k-1;
    for(;l<=r;l++, r--){
      int mx=0;
      for(char c='a'; c<='z'; c++){
        if(dp[l%k][c]+dp[r%k][c]>mx){
          dp[l%k][ans[l]]--;
	  dp[r%k][ans[r]]--;
	  ans[r]=ans[l]=c;
	  mx=dp[l%k][c]+dp[r%k][c];
          dp[l%k][ans[l]]++;
	  dp[r%k][ans[r]]++;
	}
      }
    }
  }
  for(int i=0; i<n; i++)
    if(ans[i]!=s[i])
      total++;
  cout<<total<<endl;
  //cout<<ans<<endl;
}

int main(){
  int t;
  fastio;
  cin>>t;
  for(;t>0; t--)
    solve();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T>
class MinPq: public priority_queue<T, vector<T>, greater<T> > {};
template <typename T>
class MaxPq: public priority_queue<T, vector<T>, less<T> > {};

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define sqrti(n) (int)ceil(sqrt((double)n))
#define len(a) sizeof(a)/sizeof(a[0])
#define pcase(ca,v) cout<<"Case #"<<ca+1<<": "<<v<<'\n'
#define parity(n) (n&1)
#define even(n) parity(n)==0
#define odd(n) parity(n)==1
#define inf INT_MAX
#define infl LLONG_MAX

void solve(){
  int n, k, total=0;
  string s;
  cin>>n>>k>>s;
  vector<vector<char>> dp(k, vector<char>(256));
  for(int i=0; i<n; i++){
    dp[i%k][s[i]]++;
  }
  for(int i=0, j=k-1; i<=j; i++, j--){
    int _t=0, mx=0;
    for(char c='a'; c<='z'; c++){
      _t+=dp[i][c]+dp[j][c];
      mx=max(mx, dp[i][c]+dp[j][c]);
    }
    if(i==j){
      _t/=2;
      mx/=2;
    }
    total+=_t-mx;
  }
  cout<<total<<endl;
}

void solve1(){
  int n, k, total=0;
  string s, ans;
  cin>>n>>k>>s;
  vector<vector<char>> dp(k, vector<char>(256));
  for(int i=0; i<n; i++){
    dp[i%k][s[i]]++;
    ans+=s[i];
  }
  for(int l=0, r=k-1; l<=r; l++, r--){
    int mx=0;
    char cand='a';
    for(char c='a'; c<='z'; c++){
      if(dp[l][c]+dp[r][c]>mx){
        cand=c;
	mx=dp[l][c]+dp[r][c];
      }
    }
    ans[l]=ans[r]=cand;
  }
  for(int i=k; i<n; i++){
    ans[i]=ans[i-k];
  }
  for(int i=0; i<n; i++)
    if(ans[i]!=s[i])
      total++;
  cout<<total<<endl;
}

int main(){
  int t;
  fastio;
  cin>>t;
  for(;t>0; t--)
    solve();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T>
class MinPq: public priority_queue<T, vector<T>, greater<T> > {};
template <typename T>
class MaxPq: public priority_queue<T, vector<T>, less<T> > {};

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define sqrti(n) (int)ceil(sqrt((double)n))
#define len(a) sizeof(a)/sizeof(a[0])
#define pcase(ca,v) cout<<"Case #"<<ca+1<<": "<<v<<'\n'
#define parity(n) (n&1)
#define even(n) parity(n)==0
#define odd(n) parity(n)==1
#define inf INT_MAX
#define infl LLONG_MAX

void solve(){
  int n, k, total=0;
  string s;
  cin>>n>>k>>s;
  vector<vector<int>> dp(k, vector<int>(256, 0));
  for(int i=0; i<n; i++){
    dp[i%k][s[i]]++;
  }
  for(int i=0, j=k-1; i<j; i++, j--){
    int  mx=0;
    for(char c='a'; c<='z'; c++){
      mx=max(mx, dp[i][c]+dp[j][c]);
    }
    total+=2*n/k-mx;
  }
  if(k%2){
    int mx=0;
    for(char c='a'; c<='z'; c++){
      mx=max(mx, dp[k/2][c]);
    }
    total+=n/k-mx;
  }
  cout<<total<<endl;
}

int main(){
  int t;
  fastio;
  cin>>t;
  for(;t>0; t--)
    solve();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T>
class MinPq: public priority_queue<T, vector<T>, greater<T> > {};
template <typename T>
class MaxPq: public priority_queue<T, vector<T>, less<T> > {};

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define sqrti(n) (int)ceil(sqrt((double)n))
#define len(a) sizeof(a)/sizeof(a[0])
#define pcase(ca,v) cout<<"Case #"<<ca+1<<": "<<v<<'\n'
#define parity(n) (n&1)
#define even(n) parity(n)==0
#define odd(n) parity(n)==1
#define inf INT_MAX
#define infl LLONG_MAX

void solve(){
  int n, k, total=0;
  string s;
  cin>>n>>k>>s;
  vector<vector<int>> dp(k, vector<int>(256, 0));
  for(int i=0; i<n; i++){
    dp[i%k][s[i]]++;
  }
  for(int i=0, j=k-1; i<j; i++, j--){
    int  mx=0;
    for(char c='a'; c<='z'; c++){
      mx=max(mx, dp[i][c]+dp[j][c]);
    }
    total+=2*n/k-mx;
  }
  if(k%2){
    int mx=0;
    for(char c='a'; c<='z'; c++){
      mx=max(mx, dp[k/2][c]);
    }
    total+=n/k-mx;
  }
  cout<<total<<endl;
}

void solve1(){
  int n, k, total=0;
  string s, ans;
  cin>>n>>k>>s;
  vector<vector<int>> dp(k, vector<int>(256));
  for(int i=0; i<n; i++){
    ans+=s[i];
    dp[i%k][s[i]]++;
  }
  for(int i=0; i<n; i+=k){
    int l=i, r=i+k-1;
    for(;l<=r;l++, r--){
      int mx=0;
      for(char c='a'; c<='z'; c++){
        if(dp[l%k][c]+dp[r%k][c]>mx){
	  ans[r]=ans[l]=c;
	  mx=dp[l%k][c]+dp[r%k][c];
	}
      }
    }
  }
  for(int i=0; i<n; i++)
    if(ans[i]!=s[i])
      total++;
  cout<<total<<endl;
  //cout<<ans<<endl;
}

int main(){
  int t;
  fastio;
  cin>>t;
  for(;t>0; t--)
    solve1();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T>
class MinPq: public priority_queue<T, vector<T>, greater<T> > {};
template <typename T>
class MaxPq: public priority_queue<T, vector<T>, less<T> > {};

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define sqrti(n) (int)ceil(sqrt((double)n))
#define len(a) sizeof(a)/sizeof(a[0])
#define pcase(ca,v) cout<<"Case #"<<ca+1<<": "<<v<<'\n'
#define parity(n) (n&1)
#define even(n) parity(n)==0
#define odd(n) parity(n)==1
#define inf INT_MAX
#define infl LLONG_MAX

void solve(){
  int n, k, total=0;
  string s;
  cin>>n>>k>>s;
  vector<vector<char>> dp(k, vector<char>(256));
  for(int i=0; i<n; i++){
    dp[i%k][s[i]]++;
  }
  for(int i=0, j=k-1; i<=j; i++, j--){
    int _t=0, mx=0;
    for(char c='a'; c<='z'; c++){
      _t+=dp[i][c]+dp[j][c];
      mx=max(mx, dp[i][c]+dp[j][c]);
    }
    if(i==j){
      _t/=2;
      mx/=2;
    }
    total+=_t-mx;
  }
  cout<<total<<endl;
}

void solve1(){
  int n, k, total=0;
  string s, ans;
  cin>>n>>k>>s;
  vector<vector<char>> dp(k, vector<char>(256));
  for(int i=0; i<n; i++){
    dp[i%k][s[i]]++;
    ans+=s[i];
  }
  for(int l=0, r=k-1; l<=r; l++, r--){
    int mx=0;
    char cand='a';
    for(char c='a'; c<='z'; c++){
      if(dp[l][c]+dp[r][c]>mx){
        cand=c;
	mx=dp[l][c]+dp[r][c];
      }
    }
    ans[l]=ans[r]=cand;
  }
  for(int i=k; i<n; i++){
    ans[i]=ans[i-k];
  }
  for(int i=0; i<n; i++)
    if(ans[i]!=s[i])
      total++;
  cout<<total<<endl;
}

int main(){
  int t;
  fastio;
  cin>>t;
  for(;t>0; t--)
    solve1();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T>
class MinPq: public priority_queue<T, vector<T>, greater<T> > {};
template <typename T>
class MaxPq: public priority_queue<T, vector<T>, less<T> > {};

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define sqrti(n) (int)ceil(sqrt((double)n))
#define len(a) sizeof(a)/sizeof(a[0])
#define pcase(ca,v) cout<<"Case #"<<ca+1<<": "<<v<<'\n'
#define parity(n) (n&1)
#define even(n) parity(n)==0
#define odd(n) parity(n)==1
#define inf INT_MAX
#define infl LLONG_MAX

void solve(){
  int n, k, total=0;
  string s;
  cin>>n>>k>>s;
  vector<vector<char>> dp(k, vector<char>(256, 0));
  for(int i=0; i<n; i++){
    dp[i%k][s[i]]++;
  }
  for(int i=0, j=k-1; i<j; i++, j--){
    int  mx=0;
    for(char c='a'; c<='z'; c++){
      mx=max(mx, dp[i][c]+dp[j][c]);
    }
    total+=2*n/k-mx;
  }
  if(k%2){
    int mx=0;
    for(char c='a'; c<='z'; c++){
      mx=max(mx, (int)dp[k/2][c]);
    }
    total+=n/k-mx;
  }
  cout<<total<<endl;
}

int main(){
  int t;
  fastio;
  cin>>t;
  for(;t>0; t--)
    solve();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T>
class MinPq: public priority_queue<T, vector<T>, greater<T> > {};
template <typename T>
class MaxPq: public priority_queue<T, vector<T>, less<T> > {};

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define sqrti(n) (int)ceil(sqrt((double)n))
#define len(a) sizeof(a)/sizeof(a[0])
#define pcase(ca,v) cout<<"Case #"<<ca+1<<": "<<v<<'\n'
#define parity(n) (n&1)
#define even(n) parity(n)==0
#define odd(n) parity(n)==1
#define inf INT_MAX
#define infl LLONG_MAX

void solve(){
  int n, k, total=0;
  string s, ans;
  cin>>n>>k>>s;
  vector<vector<char>> dp(k, vector<char>(256));
  for(int i=0; i<n; i++){
    ans+=s[i];
    dp[i%k][s[i]]++;
  }
  for(int i=0; i<n; i+=k){
    int l=i, r=i+k-1;
    for(;l<=r;l++, r--){
      int mx=0;
      for(char c='a'; c<='z'; c++){
        if(dp[l%k][c]+dp[r%k][c]>mx){
	  ans[r]=ans[l]=c;
	  mx=max(dp[l%k][c], dp[r%k][c]);
	}
      }
    }
  }
  for(int i=0; i<n; i++)
    if(ans[i]!=s[i])
      total++;
  cout<<total<<endl;
  //cout<<ans<<endl;
}

int main(){
  int t;
  fastio;
  cin>>t;
  for(;t>0; t--)
    solve();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T>
class MinPq: public priority_queue<T, vector<T>, greater<T> > {};
template <typename T>
class MaxPq: public priority_queue<T, vector<T>, less<T> > {};

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define sqrti(n) (int)ceil(sqrt((double)n))
#define len(a) sizeof(a)/sizeof(a[0])
#define pcase(ca,v) cout<<"Case #"<<ca+1<<": "<<v<<'\n'
#define parity(n) (n&1)
#define even(n) parity(n)==0
#define odd(n) parity(n)==1
#define inf INT_MAX
#define infl LLONG_MAX

void solve(){
  int n, k, total=0;
  string s;
  cin>>n>>k>>s;
  vector<vector<char>> dp(k, vector<char>(256, 0));
  for(int i=0; i<n; i++){
    dp[i%k][s[i]]++;
  }
  for(int i=0, j=k-1; i<j; i++, j--){
    int  mx=0;
    for(char c='a'; c<='z'; c++){
      mx=max(mx, (int)dp[i][c]+dp[j][c]);
    }
    total+=2*n/k-mx;
  }
  if(k%2){
    int mx=0;
    for(char c='a'; c<='z'; c++){
      mx=max(mx, (int)dp[k/2][c]);
    }
    total+=n/k-mx;
  }
  cout<<total<<endl;
}

int main(){
  int t;
  fastio;
  cin>>t;
  for(;t>0; t--)
    solve();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T>
class MinPq: public priority_queue<T, vector<T>, greater<T> > {};
template <typename T>
class MaxPq: public priority_queue<T, vector<T>, less<T> > {};

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define sqrti(n) (int)ceil(sqrt((double)n))
#define len(a) sizeof(a)/sizeof(a[0])
#define pcase(ca,v) cout<<"Case #"<<ca+1<<": "<<v<<'\n'
#define parity(n) (n&1)
#define even(n) parity(n)==0
#define odd(n) parity(n)==1
#define inf INT_MAX
#define infl LLONG_MAX

void solve(){
  int n, k, total=0;
  string s, ans;
  cin>>n>>k>>s;
  vector<vector<char>> dp(k, vector<char>(256));
  for(int i=0; i<n; i++){
    ans+=s[i];
    dp[i%k][s[i]]++;
  }
  for(int i=0; i<n; i+=k){
    int l=i, r=i+k-1;
    for(;l<=r;l++, r--){
      int mx=0;
      for(char c='a'; c<='z'; c++){
        if(dp[l%k][c]+dp[r%k][c]>mx){
	  ans[r]=ans[l]=c;
	  mx=dp[l%k][c]+dp[r%k][c];
	}
      }
    }
  }
  for(int i=0; i<n; i++)
    if(ans[i]!=s[i])
      total++;
  cout<<total<<endl;
  //cout<<ans<<endl;
}

int main(){
  int t;
  fastio;
  cin>>t;
  for(;t>0; t--)
    solve();
  return 0;
}


#include <bits/stdc++.h>
using namespace std;

typedef long long int ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T>
class MinPq: public priority_queue<T, vector<T>, greater<T> > {};
template <typename T>
class MaxPq: public priority_queue<T, vector<T>, less<T> > {};

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL)
#define sqrti(n) (int)ceil(sqrt((double)n))
#define len(a) sizeof(a)/sizeof(a[0])
#define pcase(ca,v) cout<<"Case #"<<ca+1<<": "<<v<<'\n'
#define parity(n) (n&1)
#define even(n) parity(n)==0
#define odd(n) parity(n)==1
#define inf INT_MAX
#define infl LLONG_MAX

void solve(){
  int n, k, total=0;
  string s;
  cin>>n>>k>>s;
  vector<vector<char>> dp(k, vector<char>(256, 0));
  for(int i=0; i<n; i++){
    dp[i%k][s[i]]++;
  }
  for(int i=0, j=k-1; i<j; i++, j--){
    int _t=0, mx=0;
    for(char c='a'; c<='z'; c++){
      _t+=dp[i][c]+dp[j][c];
      mx=max(mx, dp[i][c]+dp[j][c]);
    }
    total+=_t-mx;
  }
  int _t=0, mx=0;
  for(char c='a'; c<='z' && k%2>0; c++){
    _t+=dp[k/2][c];
    mx=max(mx, (int)dp[k/2][c]);
  }
  total+=_t-mx;
  cout<<total<<endl;
}

int main(){
  int t;
  fastio;
  cin>>t;
  for(;t>0; t--)
    solve();
  return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

/*void seive()
{
    int r=int (sqrt(mxx));
    memset(vis,false,sizeof(vis));
    prime.push_back(2);
    for(int i=4; i<=mxx; i+=2)
        vis[i]=true;
    for(int i=3; i<=r; i+=2)
    {
        if(vis[i]==false)
            for(int j=i*i; j<=mxx; j+=(i+i))
            {
                vis[j]=true;
            }
    }

    for(int i=3; i<=mxx; i++)
        if(vis[i]==false)
            prime.push_back(i);
}*/
int cnt[200005][26];

int dif_cnt(int u,int v)
{
    int cnt_alp=0,mx_frq=0;

    for(int i=0; i<26; i++)
    {
        cnt_alp+=(cnt[u][i]+cnt[v][i]);

        mx_frq=max(mx_frq,cnt[u][i]+cnt[v][i]);
    }

    return (cnt_alp-mx_frq);
}

int main()
{
    //freopen("input.txt","r",stdin);
    int t;
    cin>>t;

    while(t--)
    {
        string s;
        int n,k;

        cin>>n>>k>>s;
        memset(cnt,0,sizeof(cnt));

        for(int i=0; i<n; i++)
        {
            cnt[i%k][s[i]-'a']++;
        }

        int ans=0;
        for(int i=0; i<k; i++)
        {
            ans+=dif_cnt(i,k-1-i);
        }

        cout<<ans/2<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

/*void seive()
{
    int r=int (sqrt(mxx));
    memset(vis,false,sizeof(vis));
    prime.push_back(2);
    for(int i=4; i<=mxx; i+=2)
        vis[i]=true;
    for(int i=3; i<=r; i+=2)
    {
        if(vis[i]==false)
            for(int j=i*i; j<=mxx; j+=(i+i))
            {
                vis[j]=true;
            }
    }

    for(int i=3; i<=mxx; i++)
        if(vis[i]==false)
            prime.push_back(i);
}*/
int cnt[200005][26];

int dif_cnt(int u,int v)
{
    int cnt_alp=0,mx_frq=0;

    for(int i=0; i<26; i++)
    {
        cnt_alp+=(cnt[u][i]+cnt[v][i]);

        mx_frq=max(mx_frq,cnt[u][i]+cnt[v][i]);
    }

    return (cnt_alp-mx_frq);
}

int main()
{
    //freopen("input.txt","r",stdin);
    int t;
    cin>>t;

    while(t--)
    {
        string s;
        int n,k;

        cin>>n>>k>>s;
        for (int i=0; i<k; ++i)
        {
            for (int j=0; j<26; ++j)
            {
                cnt[i][j]=0;
            }
        }

        for(int i=0; i<n; i++)
        {
            cnt[i%k][s[i]-'a']++;
        }

        int ans=0;
        for(int i=0; i<k; i++)
        {
            ans+=dif_cnt(i,k-1-i);
        }

        cout<<ans/2<<endl;
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

/*void seive()
{
    int r=int (sqrt(mxx));
    memset(vis,false,sizeof(vis));
    prime.push_back(2);
    for(int i=4; i<=mxx; i+=2)
        vis[i]=true;
    for(int i=3; i<=r; i+=2)
    {
        if(vis[i]==false)
            for(int j=i*i; j<=mxx; j+=(i+i))
            {
                vis[j]=true;
            }
    }

    for(int i=3; i<=mxx; i++)
        if(vis[i]==false)
            prime.push_back(i);
}*/
int cnt[200005][26];

int dif_cnt(int u,int v)
{
    int cnt_alp=0,mx_frq=0;

    for(int i=0; i<26; i++)
    {
        cnt_alp+=(cnt[u][i]+cnt[v][i]);

        mx_frq=max(mx_frq,cnt[u][i]+cnt[v][i]);
    }

    return (cnt_alp-mx_frq);
}

int main()
{
    //freopen("input.txt","r",stdin);
    int t;
    scanf("%d",&t);

    while(t--)
    {
        string s;
        int n,k;

        scanf("%d%d",&n,&k);
        cin>>s;
        memset(cnt,0,sizeof(cnt));

        for(int i=0; i<n; i++)
        {
            cnt[i%k][s[i]-'a']++;
        }

        int ans=0;
        for(int i=0; i<k; i++)
        {
            ans+=dif_cnt(i,k-1-i);
        }

        printf("%d\n",ans/2);
    }

    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

/*void seive()
{
    int r=int (sqrt(mxx));
    memset(vis,false,sizeof(vis));
    prime.push_back(2);
    for(int i=4; i<=mxx; i+=2)
        vis[i]=true;
    for(int i=3; i<=r; i+=2)
    {
        if(vis[i]==false)
            for(int j=i*i; j<=mxx; j+=(i+i))
            {
                vis[j]=true;
            }
    }

    for(int i=3; i<=mxx; i++)
        if(vis[i]==false)
            prime.push_back(i);
}*/
int cnt[200005][26],vis[200005];

int dif_cnt(int u,int v)
{
    int cnt_alp=0,mx_frq=0;

    for(int i=0; i<26; i++)
    {
        cnt_alp+=(cnt[u][i]+cnt[v][i]);

        mx_frq=max(mx_frq,cnt[u][i]+cnt[v][i]);
    }

    return (cnt_alp-mx_frq);
}

int main()
{
    //freopen("input.txt","r",stdin);
    int t;
    scanf("%d",&t);

    while(t--)
    {
        string s;
        int n,k;

        scanf("%d%d",&n,&k);
        cin>>s;
        memset(cnt,0,sizeof(cnt));
        memset(vis,0,sizeof(vis));
        for(int i=0; i<n; i++)
        {
            cnt[i%k][s[i]-'a']++;
        }

        int ans=0;
        for(int i=0; i<k; i++)
        {
            ans+=dif_cnt(i,k-1-i);
        }

        printf("%d\n",ans/2);
    }

    return 0;
}


#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair <int,int>
#define mp make_pair
#define pb push_back
#define x first
#define y second/*
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/

using namespace std;

int fr[(int)2e5 + 5][26];

int solve (const int &n, const int &k, const string &s) {
    int ans = INT_MAX;
    int d = n / k;
    string w;
    w.resize(k + 1);
    for (int j, i = 1; i <= k; ++i)
        for (j = 0; j < 26; ++j)
            fr[i][j] = 0;

    for (int j, i = 1; i <= n; i += k) {
        for (j = i; j <= i + k - 1; ++j)
            ++fr[j - i + 1][s[j] - 'a'];
    }

    for (int i = 1; i <= n; i += k) {
        int j = i + k - 1;
        int t, val = 0;
        int p = i, q = j;
        while (p <= q) {
            /*if (s[p] != s[q])
                ++val;*/
            char car = s[p];
            if (fr[p - i + 1][s[p] - 'a'] < fr[q - i + 1][s[q] - 'a'])
                car = s[q];
            w[p - i + 1] = w[q - i + 1] = car;
            ++p;
            --q;
        }
        for (t = i; t <= j; ++t) {/*
            if (s[t] == w[t - i + 1]) {
                val += (d - 1 - (fr[t - i + 1][w[t - i + 1] - 'a'] - 1));
            }
            else*/
                val += (d - fr[t - i + 1][w[t - i + 1] - 'a']);

            // int cnt = 0;
            // if (s[t] == w[t - i + 1]) cnt = 1;
            // val += (d - (fr[t - i + 1][w[t - i + 1] - 'a'] - cnt));
        }
        if (val < ans) ans = val;
    }
    return ans;
}

int main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int t, n, k;
    string s;
    cin >> t;
    while (t--) {
        cin >> n >> k >> s;
        s = " " + s;
        cout << solve(n, k, s) << '\n';
    }

    return 0;
}


    #include <bits/stdc++.h>
    #define ll long long
    #define ld long double
    #define pii pair <int,int>
    #define mp make_pair
    #define pb push_back
    #define x first
    #define y second
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize ("unroll-loops")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

    using namespace std;

    const int Nmax = 2e5 + 5;

    int fr[Nmax][26];
    int n, k;
    char s[Nmax];

    void solve () {
        int ans = 0;
        for (int j, i = 1; i <= k; ++i)
            for (j = 0; j < 26; ++j)
                fr[i][j] = 0;

        for (int j, i = 1; i <= n; i += k)
            for (j = i; j <= i + k - 1; ++j)
                fr[j - i + 1][s[j] - 'a']++;

        int p = 1, q = k;
        int d = n / k;
        while (p <= q) {
            int diff = INT_MAX, val;
            for (int i = 0; i < 26; ++i){
                val = d - fr[p][i];
                if (p != q)
                    val += (d - fr[q][i]);
                diff = min(diff, val);
            }
            ans += diff;
            ++p;
            --q;
        }
        cout << ans << '\n';
    }

    int main(){
        ios_base :: sync_with_stdio(false);
        cin.tie(nullptr);
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        int t;
        cin >> t;
        while (t--) {
            cin >> n >> k >> (s + 1);
            solve();
        }

        return 0;
    }


    #include <bits/stdc++.h>
    #define ll long long
    #define ld long double
    #define pii pair <int,int>
    #define mp make_pair
    #define pb push_back
    #define x first
    #define y second/*
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize ("unroll-loops")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/

    using namespace std;

    const int Nmax = 2e5 + 5;

    int fr[Nmax][26];

    int solve (const int &n, const int &k, const string &s) {
        int ans = INT_MAX;
        int d = n / k;
        for (int j, i = 1; i <= k; ++i)
            for (j = 0; j < 26; ++j)
                fr[i][j] = 0;

        for (int j, i = 1; i <= n; i += k) {
            for (j = i; j <= i + k - 1; ++j)
                ++fr[j - i + 1][s[j] - 'a'];
        }

        for (int i = 1; i <= n; i += k) {
            int j = i + k - 1;
            int t, val = 0;
            int p = i, q = j;
            while (p <= q) {
                char car = s[p];
                if (fr[p - i + 1][s[p] - 'a'] < fr[q - i + 1][s[q] - 'a'])
                    car = s[q];
                val += (d - fr[p - i + 1][car - 'a']);
                if (p != q)
                    val += (d - fr[q - i + 1][car - 'a']);
                ++p;
                --q;
            }
            if (val < ans) ans = val;
        }
        return ans;
    }

    int main(){
        ios_base :: sync_with_stdio(false);
        cin.tie(nullptr);
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        int t, n, k;
        string s;
        cin >> t;
        while (t--) {
            cin >> n >> k >> s;
            s = " " + s;
            cout << solve(n, k, s) << '\n';
        }

        return 0;
    }


    #include <bits/stdc++.h>
    #define ll long long
    #define ld long double
    #define pii pair <int,int>
    #define mp make_pair
    #define pb push_back
    #define x first
    #define y second
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize ("unroll-loops")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

    using namespace std;

    const int Nmax = 2e5 + 5;

    int fr[Nmax][26];
    int n, k;
    char s[Nmax];

    void solve () {
        int ans = INT_MAX;
        for (int j, i = 1; i <= k; ++i)
            for (j = 0; j < 26; ++j)
                fr[i][j] = 0;

        for (int j, i = 1; i <= n; i += k)
            for (j = i; j <= i + k - 1; ++j)
                fr[j - i + 1][s[j] - 'a']++;

        for (int i = 1; i <= n; i += k) {
            int val = 0;
            int p = i, q = i + k - 1;
            while (p <= q) {
                char car = s[p];
                if (fr[p - i + 1][s[p] - 'a'] < fr[q - i + 1][s[q] - 'a'])
                    car = s[q];

                val += ((n / k) - fr[p - i + 1][car - 'a']);
                if (p != q) val += ((n / k) - fr[q - i + 1][car - 'a']);

                ++p;
                --q;
            }
            ans = min(ans, val);
        }
        cout << ans << '\n';
    }

    int main(){
        ios_base :: sync_with_stdio(false);
        cin.tie(nullptr);
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        int t;
        cin >> t;
        while (t--) {
            cin >> n >> k >> (s + 1);
            solve();
        }

        return 0;
    }


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
char s[maxn];
int res[maxn][26];
char need[maxn];

int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		memset(res, 0, sizeof res);

		int n, m;
		scanf("%d %d",&n,&m);
		scanf(" %s", s + 1);
		int cnt = n / m;
		for(int i = 0 ; i < cnt ; i++){
			for(int j = 1 ; j <= m ; j++){
				if(j <= (m + 1) / 2){
					res[j][s[i * m + j] - 'a']++;
				}
				else{
					res[m + 1 - j][s[i * m + j] - 'a']++;
				}
			}
		}

		int tmp;
		for(int i = 1 ; i <= m ; i++){
			int maxx = 0, num = 0;
			if(i <= (m + 1) / 2)tmp = i;
			else tmp = m + 1 - i;
			for(int j = 0 ; j < 26 ; j++){
				if(res[tmp][j] > maxx){
					maxx = res[tmp][j];
					num = j;
				}
			}
			need[i] = num + 'a';
			cout << need[i];
		}
		cout << endl;
		int ans = 0;
		for(int i = 0 ; i < cnt ; i++){
			for(int j = 1 ; j <= m ; j++){
				if(s[i * m + j] != need[j])ans++;
			}
		}

		printf("%d\n",ans);
	}
}


#include<bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
char s[maxn];
int res[maxn][26];
char need[maxn];

int main(){
	int T;
	scanf("%d",&T);
	while(T--){
		memset(res, 0, sizeof res);

		int n, m;
		scanf("%d %d",&n,&m);
		scanf(" %s", s + 1);
		int cnt = n / m;
		for(int i = 0 ; i < cnt ; i++){
			for(int j = 1 ; j <= m ; j++){
				if(j <= (m + 1) / 2){
					res[j][s[i * m + j] - 'a']++;
				}
				else{
					res[m + 1 - j][s[i * m + j] - 'a']++;
				}
			}
		}

		int tmp;
		for(int i = 1 ; i <= m ; i++){
			int maxx = 0, num = 0;
			if(i <= (m + 1) / 2)tmp = i;
			else tmp = m + 1 - i;
			for(int j = 0 ; j < 26 ; j++){
				if(res[tmp][j] > maxx){
					maxx = res[tmp][j];
					num = j;
				}
			}
			need[i] = num + 'a';
		}
		int ans = 0;
		for(int i = 0 ; i < cnt ; i++){
			for(int j = 1 ; j <= m ; j++){
				if(s[i * m + j] != need[j])ans++;
			}
		}

		printf("%d\n",ans);
	}
}