/*勺子只能是10*20,每一个格子是10*10,所以符合条件的肯定是成对存在的
  取每一个点坐标的x,y值,看奇偶数的累加,取奇偶的最小值
*/

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
const int N = 55;
char Map[N][N];
int n;
int vis[N][N];
int a,b;
int Next[4][2]={-1,0,1,0,0,1,0,-1};

void dfs(int x,int y){
    Map[x][y] = '.';
    if ((x + y) % 2 == 0) a ++;
    else b ++;
    for(int i = 0; i < 4; i ++){
        int tx = x + Next[i][0];
        int ty = y + Next[i][1];
        if(tx >= 0 && tx < n && ty >=0 && ty < n && Map[tx][ty] == '#'){
            dfs(tx,ty);
        }
    }
}
int main(){
    int t;
    scanf("%d",&t);
    int cas = 1;
    while(t--){
        memset(vis,0,sizeof(vis));
        scanf("%d",&n);
        for(int i = 0; i < n; i ++){
            scanf("%s",Map[i]);
        }
        int ans = 0;
        for(int i = 0;i < n; i ++){
            for(int j = 0; j < n; j ++){
                    if(Map[i][j] == '#'){
                        a = 0;
                        b = 0;
                        dfs(i,j);
                        ans += min(a,b);
                    }
            }
        }
        printf("Case %d: %d",cas ++,ans);
    }
    return 0;
}