#include <iostream>
#include <string.h>
#include <algorithm>
#include <stdio.h>
using namespace std;
const int N=110;
int dir[4][2]={1,0,-1,0,0,1,0,-1};
int map[N][N];
char array[N][N];
int h,w;
void dfs(int x,int y){
if(x<0||y<0||x>=h||y>=w)
return;
if(array[x][y]=='#'&&map[x][y]==0)
map[x][y]=1;
else
return;
int i,j,k;
for(k=0;k<4;k++){
i=x+dir[k][0];
j=y+dir[k][1];
dfs(i,j);
}
}
int main(){
int t,i,j,k;
int count;
scanf("%d",&t);
while(t--){
memset(map,0,sizeof(map));
scanf("%d %d",&h,&w);
for(i=0;i<h;i++){
scanf("%s",array[i]);
}
count=0;
for(i=0;i<h;i++){
for(j=0;j<w;j++){
if(array[i][j]=='#'&&map[i][j]==0){
++count;
dfs(i,j);
}
}
}
printf("%d\n",count);
}
return 0;
}