#include<bits/stdc++.h>
using namespace std;
#define ll long long
signed main()
{
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t;cin>>t;while(t--)
{
int n,m;cin>>n>>m;
char s[n][m];
int r[n]={},c[m]={};
for(int i=0;i<n;i++)
{
for(int o=0;o<m;o++)
{
cin>>s[i][o];
if(s[i][o]=='#')
{
r[i]++;
c[o]++;
}
}
}
int ans=0;
for(int i=0;i<n;i++)
{
for(int o=0;o<m;o++)
{
if(s[i][o]=='#')
{
ans+=r[i]==n&&c[o]==m;
}
else
{
ans+=r[i]==n-1&&c[o]==m-1;
}
}
}
cout<<ans<<'\n';
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKI2RlZmluZSBsbCBsb25nIGxvbmcKc2lnbmVkIG1haW4oKQp7CiAgICBpb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKDApO2Npbi50aWUoMCk7Y291dC50aWUoMCk7CiAgICBpbnQgdDtjaW4+PnQ7d2hpbGUodC0tKQogICAgewogICAgICAgIGludCBuLG07Y2luPj5uPj5tOwogICAgICAgIGNoYXIgc1tuXVttXTsKICAgICAgICBpbnQgcltuXT17fSxjW21dPXt9OwogICAgICAgIGZvcihpbnQgaT0wO2k8bjtpKyspCiAgICAgICAgewogICAgICAgICAgICBmb3IoaW50IG89MDtvPG07bysrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBjaW4+PnNbaV1bb107CiAgICAgICAgICAgICAgICBpZihzW2ldW29dPT0nIycpCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgcltpXSsrOwogICAgICAgICAgICAgICAgICAgIGNbb10rKzsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBpbnQgYW5zPTA7CiAgICAgICAgZm9yKGludCBpPTA7aTxuO2krKykKICAgICAgICB7CiAgICAgICAgICAgIGZvcihpbnQgbz0wO288bTtvKyspCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGlmKHNbaV1bb109PScjJykKICAgICAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgICAgICBhbnMrPXJbaV09PW4mJmNbb109PW07CiAgICAgICAgICAgICAgICB9CiAgICAgICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICB7CiAgICAgICAgICAgICAgICAgICAgYW5zKz1yW2ldPT1uLTEmJmNbb109PW0tMTsKICAgICAgICAgICAgICAgIH0KICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBjb3V0PDxhbnM8PCdcbic7CiAgICB9CiAgICByZXR1cm4gMDsKfQ==