#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define PI 3.1415926535897932384
#define fastio std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define int long long
int dp[1005][3][2];
int findans(int i, int j, int state, vector <string> vv, int n){
if(i >= n || i < 0 || j < 0 || j >= 3) return 0;
if(i == n-1 && j == 2 && state == 1) return 1;
int ans = 0;
if(state){
if(i+1 < n && vv[j][i+1] != '#'){
if(dp[i+1][j][1-state] != -1)
ans = (ans + dp[i+1][j][1-state])%MOD;
else
ans = (ans + findans(i+1, j, 1-state, vv, n))%MOD;
}
return dp[i][j][state] = ans;
}
else{
if(j+1 < 3 && vv[j+1][i] != '#'){
if(dp[i][j+1][1-state] != -1)
ans = (ans + dp[i][j+1][1-state])%MOD;
else
ans = (ans + findans(i, j+1, 1-state, vv, n))%MOD;
}
if(j-1 >= 0 && vv[j-1][i] != '#'){
if(dp[i][j-1][1-state] != -1)
ans = (ans + dp[i][j-1][1-state]);
else
ans = (ans + findans(i, j-1, 1-state, vv, n))%MOD;
}
return dp[i][j][state] = ans;
}
return 0;
}
void solve(int t){
int n;
cin >> n;
vector <string> vv;
string s;
cin >> s; vv.push_back(s);
cin >> s; vv.push_back(s);
cin >> s; vv.push_back(s);
cout << "Case #" << t << ": ";
//bool visited;
for(int i = 0; i < n; i++){
for(int j = 0; j < 3; j++){
for(int k = 0; k < 2; k++){
dp[i][j][k] = -1;
}
}
}
cout << findans(0, 0, 0, vv, n) << "\n";
}
signed main(){
fastio;
int t;
cin >> t;
for(int i = 1; i <= t; i++){
solve(i);
}
return 0;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KdXNpbmcgbmFtZXNwYWNlIHN0ZDsKCiNkZWZpbmUgTU9EIDEwMDAwMDAwMDcKI2RlZmluZSBQSSAzLjE0MTU5MjY1MzU4OTc5MzIzODQKI2RlZmluZSBmYXN0aW8gc3RkOjppb3NfYmFzZTo6c3luY193aXRoX3N0ZGlvKGZhbHNlKTsgY2luLnRpZSgwKTsgY291dC50aWUoMCk7CiNkZWZpbmUgaW50IGxvbmcgbG9uZwoKaW50IGRwWzEwMDVdWzNdWzJdOwoKaW50IGZpbmRhbnMoaW50IGksIGludCBqLCBpbnQgc3RhdGUsIHZlY3RvciA8c3RyaW5nPiB2diwgaW50IG4pewoKCiAgICBpZihpID49IG4gfHwgaSA8IDAgfHwgaiA8IDAgfHwgaiA+PSAzKSByZXR1cm4gMDsKICAgIGlmKGkgPT0gbi0xICYmIGogPT0gMiAmJiBzdGF0ZSA9PSAxKSAgIHJldHVybiAxOwogICAgaW50IGFucyA9IDA7CiAgICBpZihzdGF0ZSl7CiAgICAgICAgaWYoaSsxIDwgbiAmJiB2dltqXVtpKzFdICE9ICcjJyl7CiAgICAgICAgICAgIGlmKGRwW2krMV1bal1bMS1zdGF0ZV0gIT0gLTEpCiAgICAgICAgICAgICAgICBhbnMgPSAoYW5zICsgZHBbaSsxXVtqXVsxLXN0YXRlXSklTU9EOwogICAgICAgICAgICBlbHNlCiAgICAgICAgICAgICAgICBhbnMgPSAoYW5zICsgZmluZGFucyhpKzEsIGosIDEtc3RhdGUsIHZ2LCBuKSklTU9EOwogICAgICAgIH0KICAgICAgICByZXR1cm4gZHBbaV1bal1bc3RhdGVdID0gYW5zOwogICAgfQogICAgZWxzZXsKICAgICAgICBpZihqKzEgPCAzICYmIHZ2W2orMV1baV0gIT0gJyMnKXsKICAgICAgICAgICAgaWYoZHBbaV1baisxXVsxLXN0YXRlXSAhPSAtMSkKICAgICAgICAgICAgICAgIGFucyA9IChhbnMgKyBkcFtpXVtqKzFdWzEtc3RhdGVdKSVNT0Q7CiAgICAgICAgICAgIGVsc2UKICAgICAgICAgICAgICAgIGFucyA9IChhbnMgKyBmaW5kYW5zKGksIGorMSwgMS1zdGF0ZSwgdnYsIG4pKSVNT0Q7CiAgICAgICAgfQogICAgICAgIGlmKGotMSA+PSAwICYmIHZ2W2otMV1baV0gIT0gJyMnKXsKICAgICAgICAgICAgaWYoZHBbaV1bai0xXVsxLXN0YXRlXSAhPSAtMSkKICAgICAgICAgICAgICAgIGFucyA9IChhbnMgKyBkcFtpXVtqLTFdWzEtc3RhdGVdKTsKICAgICAgICAgICAgZWxzZQogICAgICAgICAgICAgICAgYW5zID0gKGFucyArIGZpbmRhbnMoaSwgai0xLCAxLXN0YXRlLCB2diwgbikpJU1PRDsKICAgICAgICB9CiAgICAgICAgcmV0dXJuIGRwW2ldW2pdW3N0YXRlXSA9IGFuczsKICAgIH0KICAgIHJldHVybiAwOwp9Cgp2b2lkIHNvbHZlKGludCB0KXsKICAgIGludCBuOwogICAgY2luID4+IG47CiAgICB2ZWN0b3IgPHN0cmluZz4gdnY7CiAgICBzdHJpbmcgczsKICAgIGNpbiA+PiBzOyB2di5wdXNoX2JhY2socyk7CiAgICBjaW4gPj4gczsgdnYucHVzaF9iYWNrKHMpOwogICAgY2luID4+IHM7IHZ2LnB1c2hfYmFjayhzKTsKCiAgICBjb3V0IDw8ICJDYXNlICMiIDw8IHQgPDwgIjogIjsKICAgIC8vYm9vbCB2aXNpdGVkOwogICAgZm9yKGludCBpID0gMDsgaSA8IG47IGkrKyl7CiAgICAgICAgZm9yKGludCBqID0gMDsgaiA8IDM7IGorKyl7CiAgICAgICAgICAgIGZvcihpbnQgayA9IDA7IGsgPCAyOyBrKyspewogICAgICAgICAgICAgICAgZHBbaV1bal1ba10gPSAtMTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgIH0KCiAgICBjb3V0IDw8IGZpbmRhbnMoMCwgMCwgMCwgdnYsIG4pIDw8ICJcbiI7Cgp9CgpzaWduZWQgbWFpbigpewoKICAgIGZhc3RpbzsKICAgIAogICAgaW50IHQ7CiAgICBjaW4gPj4gdDsKICAgIGZvcihpbnQgaSA9IDE7IGkgPD0gdDsgaSsrKXsKICAgICAgICBzb2x2ZShpKTsKICAgIH0KICAgIAogICAgcmV0dXJuIDA7Cn0K