#include <bits/stdc++.h>
#pragma GCC optimize(2)
using namespace std;
inline long long read() {
  long long f = 1, x = 0;
  char s = getchar();
  while (s < '0' || s > '9') {
    if (s == '-') f = -1;
    s = getchar();
  }
  while (s >= '0' && s <= '9') {
    x = x * 10 + (s - '0');
    s = getchar();
  }
  return x * f;
}
const int jzm = 1000000007;
int n, m, i, j, s, o, k;
int w[10], f[1007];
char ss[1007];
int mx[10][10];
int dp[2][1 << 16 | 5];
int main() {
  n = read();
  for (int i = 1; i <= 4; i++) w[i] = read();
  for (int i = 1; i <= 4; i++) {
    scanf("%s", ss + 1);
    for (int j = 1; j <= n; j++) {
      f[j] = (f[j] << 1) + (ss[j] == '*' ? 0 : 1);
    }
    f[n + 1] = 15;
    f[n + 2] = 15;
    f[n + 3] = 15;
    f[n + 4] = 15;
    f[n + 5] = 15;
  }
  for (int i = 1; i <= 4; i++) {
    int ff = 0;
    for (int j = 3; j > 3 - i; j--) {
      ff |= (1 << j);
    }
    for (int j = 1; j <= i; j++) {
      (mx[1][i] <<= 4) += ff;
    }
    for (int j = 2; j + i - 1 <= 4; j++) {
      mx[j][i] = mx[j - 1][i] >> 1;
    }
  }
  int tp = (1 << 16) - 1, k1 = 0;
  for (int i = 4; i > 0; i--) {
    k1 = (k1 << 4) + f[i];
  }
  memset(dp, 0x3f, sizeof(dp));
  int maxn = dp[0][0];
  dp[1][k1] = 0;
  for (int i = 1; i <= n; i++, k1 = (k1 >> 4) + (f[i + 3] << 12)) {
    memset(dp[i + 1 & 1], 0x3f, sizeof(dp[0]));
    for (int j = k1; j <= tp; j++) {
      if (dp[i & 1][j] < maxn && (j & k1) == k1) {
        if (((j)&15) == 15) {
          int jjj = (j >> 4) + (f[i + 4] << 12);
          dp[i + 1 & 1][jjj] = min(dp[i + 1 & 1][jjj], dp[i & 1][j]);
        }
        for (int k = 1; k <= 4; k++) {
          for (int l = 1; l + k - 1 <= 4; l++) {
            int jj = j | mx[l][k];
            dp[i & 1][jj] = min(dp[i & 1][jj], dp[i & 1][j] + w[k]);
            if (((jj)&15) == 15) {
              int jjj = (jj >> 4) + (f[i + 4] << 12);
              dp[i + 1 & 1][jjj] = min(dp[i + 1 & 1][jjj], dp[i & 1][jj]);
            }
          }
        }
      }
    }
  }
  printf("%d\n", dp[n + 1 & 1][tp]);
  return 0;
}
