#include <bits/stdc++.h>
using namespace std;
const int MAX = 1010;
const int NONE = 0;
const int HAS_BACK = 1;
const int HAS_BACK_USED = 2;
char mat[2][MAX];
int n;
int dp[MAX][3][3]; // pos, top row state, bottom row state
int Go(int pos, int st0, int st1) {
if (pos == n)
return 0;
int& ret = dp[pos][st0][st1];
int cost, new_state;
if (ret == -1) {
ret = 1 << 30;
if (mat[0][pos] == 'X') {
if (mat[1][pos] == 'X') {
ret = Go(pos+1, NONE, NONE);
} else {
if (st1 == NONE) {
new_state = HAS_BACK;
cost = 1;
} else {
new_state = st1;
cost = 0;
}
ret = cost + Go(pos+1, NONE, new_state);
}
} else {
if (mat[1][pos] == 'X') {
if (st0 == NONE) {
new_state = HAS_BACK;
cost = 1;
} else {
new_state = st0;
cost = 0;
}
ret = cost + Go(pos+1, new_state, NONE);
} else {
// both free squares.
if (st0 != NONE && st1 != NONE) {
ret = Go(pos+1, st0, st1);
} else if (st0 == NONE && st1 == NONE) {
// put on top row or bottom row
ret = 1 + min(Go(pos+1, HAS_BACK_USED, NONE), Go(pos+1, NONE, HAS_BACK_USED));
} else if (st0 != NONE) {
if (st0 == HAS_BACK)
ret = Go(pos+1, HAS_BACK_USED, NONE);
ret = min(ret, 1 + Go(pos+1, st0, HAS_BACK));
} else {
if (st1 == HAS_BACK)
ret = Go(pos+1, NONE, HAS_BACK_USED);
ret = min(ret, 1 + Go(pos+1, HAS_BACK, st1));
}
}
}
}
return ret;
}
int Solve() {
scanf("%d %s %s", &n, mat[0], mat[1]);
memset(dp, -1, sizeof dp);
return Go(0, NONE, NONE);
}
int main() {
int ntests;
scanf("%d", &ntests);
for (int nt = 1; nt <= ntests; ++nt) {
printf("Case #%d: %d\n", nt, Solve());
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmNvbnN0IGludCBNQVggPSAxMDEwOwpjb25zdCBpbnQgTk9ORSA9IDA7CmNvbnN0IGludCBIQVNfQkFDSyA9IDE7CmNvbnN0IGludCBIQVNfQkFDS19VU0VEID0gMjsKCmNoYXIgbWF0WzJdW01BWF07CmludCBuOwppbnQgZHBbTUFYXVszXVszXTsgLy8gcG9zLCB0b3Agcm93IHN0YXRlLCBib3R0b20gcm93IHN0YXRlCgppbnQgR28oaW50IHBvcywgaW50IHN0MCwgaW50IHN0MSkgewogIGlmIChwb3MgPT0gbikKICAgIHJldHVybiAwOwogIGludCYgcmV0ID0gZHBbcG9zXVtzdDBdW3N0MV07CiAgaW50IGNvc3QsIG5ld19zdGF0ZTsKICBpZiAocmV0ID09IC0xKSB7CiAgICByZXQgPSAxIDw8IDMwOwogICAgaWYgKG1hdFswXVtwb3NdID09ICdYJykgewogICAgICBpZiAobWF0WzFdW3Bvc10gPT0gJ1gnKSB7CiAgICAgICAgcmV0ID0gR28ocG9zKzEsIE5PTkUsIE5PTkUpOwogICAgICB9IGVsc2UgewogICAgICAgIGlmIChzdDEgPT0gTk9ORSkgewogICAgICAgICAgbmV3X3N0YXRlID0gSEFTX0JBQ0s7CiAgICAgICAgICBjb3N0ID0gMTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgbmV3X3N0YXRlID0gc3QxOwogICAgICAgICAgY29zdCA9IDA7CiAgICAgICAgfQogICAgICAgIHJldCA9IGNvc3QgKyBHbyhwb3MrMSwgTk9ORSwgbmV3X3N0YXRlKTsKICAgICAgfQogICAgfSBlbHNlIHsKICAgICAgaWYgKG1hdFsxXVtwb3NdID09ICdYJykgewogICAgICAgIGlmIChzdDAgPT0gTk9ORSkgewogICAgICAgICAgbmV3X3N0YXRlID0gSEFTX0JBQ0s7CiAgICAgICAgICBjb3N0ID0gMTsKICAgICAgICB9IGVsc2UgewogICAgICAgICAgbmV3X3N0YXRlID0gc3QwOwogICAgICAgICAgY29zdCA9IDA7CiAgICAgICAgfQogICAgICAgIHJldCA9IGNvc3QgKyBHbyhwb3MrMSwgbmV3X3N0YXRlLCBOT05FKTsKICAgICAgfSBlbHNlIH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