#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
#define fi first
#define sec second
const int MAX = 1005;
const int mod = 1e9 + 7;
inline long long add(long long a, long long b) {
long long c = a + b;
return (c >= mod ? c - mod : c);
}
inline long long sub(long long a, long long b) {
long long c = a - b;
return (c < 0 ? c + mod : c);
}
inline long long mul(long long a, long long b) {
long long c = a * b;
return (c >= mod ? c % mod : c);
}
int n;
string s[3];
int vis[3][MAX];
long long dp[3][MAX][4][4];
int pipe[4][4];
pair<pii, pair<pii, pii>> trans[4][4];
void init() {
// index, entry
// entry, leave, go, candidate(pipe, entry)
for(int i = 0; i < 4; ++i) {
for(int j = 0; j < 4; ++j) {
pipe[i][j] = -1;
trans[i][j] = {{0, 0}, {{-1, -1}, {-1, -1}}};
}
}
pipe[0][3] = 2;
pipe[0][2] = 3;
pipe[1][1] = 2;
pipe[1][2] = 1;
pipe[2][0] = 1;
pipe[2][1] = 0;
pipe[3][3] = 0;
pipe[3][0] = 3;
trans[0][1] = {{0, 1}, {{0, 3}, {3, 3}}};
trans[0][3] = {{0, -1}, {{1, 1}, {2, 1}}};
trans[1][0] = {{-1, 0}, {{0, 2}, {1, 2}}};
trans[1][2] = {{1, 0}, {{2, 0}, {3, 0}}};
trans[2][1] = {{0, 1}, {{0, 3}, {3, 3}}};
trans[2][3] = {{0, -1}, {{1, 1}, {2, 1}}};
trans[3][0] = {{-1, 0}, {{0, 2}, {1, 2}}};
trans[3][2] = {{1, 0}, {{2, 0}, {3, 0}}};
}
long long rec(int pos_x, int pos_y, int enter, int leave) {
// cout << pos_x << " " << pos_y << " " << enter << " " << leave << "\n";
if (pos_x < 0 || pos_x >= 3) {
// cout << "err 1\n";
return 0;
}
if (pos_y < 0 || pos_y >= n) {
// cout << "err 2\n";
return 0;
}
if (vis[pos_x][pos_y]) {
// cout << "err 3\n";
return 0;
}
if (s[pos_x][pos_y] == '#') {
// cout << "err 4\n";
return 0;
}
if (pos_x == 2 && pos_y == (n-1)) {
// cout << "Came " << leave << "\n";
if (leave == 1) {
return 1;
}
return 0;
}
long long &res = dp[pos_x][pos_y][enter][leave];
if (res != -1) {
return res;
}
res = 0;
auto get = trans[enter][leave];
pii go = get.fi;
auto can = get.sec;
vis[pos_x][pos_y] = 1;
res = add(res, rec(pos_x + go.fi, pos_y + go.sec,
can.fi.sec, pipe[can.fi.fi][can.fi.sec]));
vis[pos_x][pos_y] = 0;
vis[pos_x][pos_y] = 1;
res = add(res, rec(pos_x + go.fi, pos_y + go.sec,
can.sec.sec, pipe[can.sec.fi][can.sec.sec]));
vis[pos_x][pos_y] = 0;
return res;
}
int main() {
ios_base::sync_with_stdio(false);
init();
int T;
cin >> T;
for(int t = 1; t <= T; ++t) {
cin >> n;
cin >> s[0] >> s[1] >> s[2];
for(int i = 0; i < 3; ++i) {
for(int j = 0; j < n; ++j) {
vis[i][j] = 0;
for(int k = 0; k < 4; ++k) {
for(int l = 0; l < 4; ++l) {
dp[i][j][k][l] = -1;
}
}
}
}
long long ans = rec(0, 0, 1, 2);
cout << "Case #" << t << ": " << ans << "\n";
}
return 0;
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7Cgp0eXBlZGVmIHBhaXI8aW50LGludD4gcGlpOwoKI2RlZmluZSBmaSBmaXJzdAojZGVmaW5lIHNlYyBzZWNvbmQKCmNvbnN0IGludCBNQVggPSAxMDA1Owpjb25zdCBpbnQgbW9kID0gMWU5ICsgNzsKCmlubGluZSBsb25nIGxvbmcgYWRkKGxvbmcgbG9uZyBhLCBsb25nIGxvbmcgYikgewogIGxvbmcgbG9uZyBjID0gYSArIGI7CiAgcmV0dXJuIChjID49IG1vZCA/IGMgLSBtb2QgOiBjKTsKfQoKaW5saW5lIGxvbmcgbG9uZyBzdWIobG9uZyBsb25nIGEsIGxvbmcgbG9uZyBiKSB7CiAgbG9uZyBsb25nIGMgPSBhIC0gYjsKICByZXR1cm4gKGMgPCAwID8gYyArIG1vZCA6IGMpOw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jKDAsIDAsIDEsIDIpOwogICAgY291dCA8PCAiQ2FzZSAjIiA8PCB0IDw8ICI6ICIgPDwgYW5zIDw8ICJcbiI7CiAgfQogIHJldHVybiAwOwp9