#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
char c[45][15];
int data[45][15],count,M;
int edge[405][405],link[405],visit[405];
bool hungery(int m){
for(int i=1;i<=count;i++){
if(edge[m][i]&&!visit[i]){
visit[i] = 1;
if(link[i]==0||hungery(link[i])){
link[i] = m;
return true;
}
}
}
return false;
}
void search(){
M = 0;
for(int i=1;i<=count;i++){
memset(visit,0,sizeof visit);
if(hungery(i)){
M++;
}
}
}
int main(){
int n,h,w,i,j;
scanf("%d",&n);
while(n--){
memset(edge,0,sizeof edge);
memset(link,0,sizeof link);
scanf("%d%d",&h,&w);
count = 0;
for(i=1;i<=h;i++){
scanf("%s",c[i]);
for(j=1;j<=w;j++){
if(c[i][j-1]=='*')data[i][j] = ++count;
else data[i][j] = 0;
}
}
for(i=1;i<=h;i++){
for(j=1;j<=w;j++){
if(data[i][j]){
if(i+1<=h&&data[i+1][j]){
edge[data[i][j]][data[i+1][j]] = true;
}
if(i-1>0&&data[i-1][j]){
edge[data[i][j]][data[i-1][j]] = true;
}
if(j+1<=w&&data[i][j+1]){
edge[data[i][j]][data[i][j+1]] = true;
}
if(j-1>0&&data[i][j-1]){
edge[data[i][j]][data[i][j-1]] = true;
}
}
}
}
search();
printf("%d\n",count-M/2);
}
return 0;
}