#include <bits/stdc++.h>
using namespace std;
const int dir[8][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1},
                       {2, 0}, {0, 2}, {-2, 0}, {0, -2}};
void read(long long &x) {
  x = 0;
  long long f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -f;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = (x << 1) + (x << 3) + c - '0';
    c = getchar();
  }
  x *= f;
  return;
}
long long fs(long long x) { return x < 0 ? -x : x; }
void print(long long x) {
  if (x < 10) {
    putchar(x + '0');
    return;
  }
  print(x / 10);
  putchar(x % 10 + '0');
  return;
}
void write(long long x) {
  if (x < 0) {
    putchar('-');
    x = fs(x);
  }
  print(x);
  return;
}
long long mint(long long x, long long y) { return x < y ? x : y; }
long long maxt(long long x, long long y) { return x > y ? x : y; }
char c[10005][4];
long long n, dp[10005][8], cx, cy, px, py, ans;
bool vis[4];
bool check() {
  return px > 0 && py > 0 && px <= n && py <= 3 && c[px][py] != 'X';
}
long long get_ans() {
  memset(dp, 0, sizeof(dp));
  dp[0][7] = 1;
  for (int i = 1; i <= n; i++) {
    long long tmp = 0;
    for (int j = 0; j < 8; j++) {
      if (j == 0) dp[i][j] = dp[i - 1][7];
      if (j == 1) dp[i][j] = dp[i - 1][6];
      if (j == 2) dp[i][j] = dp[i - 1][5];
      if (j == 3) dp[i][j] = (dp[i - 1][7] + dp[i - 1][4]) % 1000000007;
      if (j == 4) dp[i][j] = dp[i - 1][3];
      if (j == 5) dp[i][j] = dp[i - 1][2];
      if (j == 6) dp[i][j] = (dp[i - 1][1] + dp[i - 1][7]) % 1000000007;
      if (j == 7)
        dp[i][j] = (dp[i - 1][0] + dp[i - 1][3] + dp[i - 1][6]) % 1000000007;
    }
    for (int j = 0; j < 3; j++)
      if (c[i][j + 1] == 'X') tmp |= (1 << j);
    if (!tmp) continue;
    long long tp[8];
    for (int j = 0; j < 8; j++) tp[j] = 0;
    for (int j = 0; j < 8; j++)
      if ((j ^ tmp) == (j - tmp)) tp[j] = dp[i][j ^ tmp];
    for (int j = 0; j < 8; j++) dp[i][j] = tp[j];
  }
  return dp[n][7];
}
int main() {
  read(n);
  for (int j = 1; j <= 3; j++) {
    for (int i = 1; i <= n; i++) {
      c[i][j] = getchar();
      if (c[i][j] == 'O') {
        cx = i;
        cy = j;
        c[i][j] = 'X';
      }
    }
    c[0][0] = getchar();
  }
  for (int i = 0; i < 8; i++) {
    bool f = 0;
    px = cx + dir[i][0];
    py = cy + dir[i][1];
    if (!check()) vis[i % 4] = 1;
  }
  for (int i = 1; i < 16; i++) {
    bool f = 0;
    long long cnt = 0;
    for (int j = 0; j < 4; j++) {
      if (i & (1 << j) && !vis[j]) {
        c[cx + dir[j][0]][cy + dir[j][1]] =
            c[cx + dir[j + 4][0]][cy + dir[j + 4][1]] = 'X';
        cnt++;
      }
      if (i & (1 << j) && vis[j]) f = 1;
    }
    if (!f)
      ans = (ans + (cnt % 2 ? 1 : -1) * get_ans() + 1000000007) % 1000000007;
    for (int j = 0; j < 4; j++)
      if (!vis[j])
        c[cx + dir[j][0]][cy + dir[j][1]] =
            c[cx + dir[j + 4][0]][cy + dir[j + 4][1]] = '.';
  }
  printf("%lld\n", ans);
}
