#include <bits/stdc++.h>
using namespace std;
const int N = 405;
struct edge {
int to, c;
};
int n;
string str[N];
vector<edge> G[N];
int vis[N];
int cnt[2];
void dfs(int v, int c) {
vis[v] = c;
cnt[c]++;
for(auto e : G[v]) {
if(vis[e.to] == -1) dfs(e.to, e.c ^ c);
if(vis[e.to] != -1) assert(vis[e.to] == (e.c ^ c));
}
}
void solve(int t) {
cin >> n;
for(int i = 0; i < n; i++) cin >> str[i];
for(int i = 0; i < 4 * n - 2; i++) G[i].clear();
for(int i = 0; i < n; i++) {
for(int j = 0; j < n; j++) {
int u = i + j, v = 2 * n - 1 + (i + (n - 1) - j);
G[u].push_back({v, str[i][j] == '.'});
G[v].push_back({u, str[i][j] == '.'});
}
}
fill(vis, vis + 4 * n - 2, -1);
int res = 0;
for(int i = 0; i < 4 * n - 2; i++) {
if(vis[i] == -1) {
cnt[0] = cnt[1] = 0;
dfs(i, 0);
res += min(cnt[0], cnt[1]);
}
}
cout << "Case #" << t << ": " << res << '\n';
}
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int T;
cin >> T;
for(int t = 1; t <= T; t++) {
solve(t);
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgpjb25zdCBpbnQgTiA9IDQwNTsKCnN0cnVjdCBlZGdlIHsKICAgIGludCB0bywgYzsKfTsKCmludCBuOwpzdHJpbmcgc3RyW05dOwp2ZWN0b3I8ZWRnZT4gR1tOXTsKaW50IHZpc1tOXTsKaW50IGNudFsyXTsKCnZvaWQgZGZzKGludCB2LCBpbnQgYykgewogICAgdmlzW3ZdID0gYzsKICAgIGNudFtjXSsrOwogICAgZm9yKGF1dG8gZSA6IEdbdl0pIHsKICAgICAgICBpZih2aXNbZS50b10gPT0gLTEpIGRmcyhlLnRvLCBlLmMgXiBjKTsKICAgICAgICBpZih2aXNbZS50b10gIT0gLTEpIGFzc2VydCh2aXNbZS50b10gPT0gKGUuYyBeIGMpKTsKICAgIH0KfQoKdm9pZCBzb2x2ZShpbnQgdCkgewogICAgY2luID4+IG47CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSBjaW4gPj4gc3RyW2ldOwogICAgZm9yKGludCBpID0gMDsgaSA8IDQgKiBuIC0gMjsgaSsrKSBHW2ldLmNsZWFyKCk7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgbjsgaSsrKSB7CiAgICAgICAgZm9yKGludCBqID0gMDsgaiA8IG47IGorKykgewogICAgICAgICAgICBpbnQgdSA9IGkgKyBqLCB2ID0gMiAqIG4gLSAxICsgKGkgKyAobiAtIDEpIC0gaik7CiAgICAgICAgICAgIEdbdV0ucHVzaF9iYWNrKHt2LCBzdHJbaV1bal0gPT0gJy4nfSk7CiAgICAgICAgICAgIEdbdl0ucHVzaF9iYWNrKHt1LCBzdHJbaV1bal0gPT0gJy4nfSk7CiAgICAgICAgfQogICAgfQogICAgZmlsbCh2aXMsIHZpcyArIDQgKiBuIC0gMiwgLTEpOwogICAgaW50IHJlcyA9IDA7CiAgICBmb3IoaW50IGkgPSAwOyBpIDwgNCAqIG4gLSAyOyBpKyspIHsKICAgICAgICBpZih2aXNbaV0gPT0gLTEpIHsKICAgICAgICAgICAgY250WzBdID0gY250WzFdID0gMDsKICAgICAgICAgICAgZGZzKGksIDApOwogICAgICAgICAgICByZXMgKz0gbWluKGNudFswXSwgY250WzFdKTsKICAgICAgICB9CiAgICB9CiAgICBjb3V0IDw8ICJDYXNlICMiIDw8IHQgPDwgIjogIiA8PCByZXMgPDwgJ1xuJzsKfQoKaW50IG1haW4oKSB7CiAgICBpb3M6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7CiAgICBjaW4udGllKE5VTEwpOwoKICAgIGludCBUOwogICAgY2luID4+IFQ7CiAgICBmb3IoaW50IHQgPSAxOyB0IDw9IFQ7IHQrKykgewogICAgICAgIHNvbHZlKHQpOwogICAgfQoKfQ==